PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Effective exceptions

I believe that the most common problem with program debugging is that you don't actually see the people who run your program :).
All you have - only a few words from them, and a logfile.

So the problem is this: to actually know exactly what happened when your program hanged on user with no adequate reason or explanation.

And what I want to discuss here is what you guys do with this problem.

I'm personally using logging, but it's very slow, so you can't just logg every function, at least in a game. I may know that it happened somewhere in a main cycle after the game mode is changed and all stuff properly loaded, and that's it.

Maybe there's something wrong with my logging function, I'm openning and closing log file every time, because I think that if the program hangs, it won't log last messages, so the logging will be useless.

So I'm now trying to implement exceptions handling, which I never did.

I wrote a few macros for them, I didn't have a chace to test them well, and I also probably need an example of proper exceptions filter(I don't know how to print what kind of exception really happened).

Here are my macros:

Code:
#ifdef EXCEPTIONS_ENABLE
#define MY_EXCEPT_START \
__try {

#define MY_EXCEPT_END(expr) \
} __except (1) \
{LoggEx(_T("Exception in %s"), expr);}
#else
#define MY_EXCEPT_START
#define MY_EXCEPT_END(expr)
#endif


Any comments on them are welcome.

So, what I do is this: every main cycle routine I envelop with this macros like this:

Code:
MY_EXCEPT_START
Flyer.Process(dt);
MY_EXCEPT_END(_T("Flyer.Process"));

MY_EXCEPT_START
ProcessMapActiveObjects(dt);
MY_EXCEPT_END(_T("ProcessMapActiveObjects"));


Looks ugly, but should probably work, I suppose.
The best thing would be a call stack, but this probably is impossible. Memory dump, using which I could determine the call stack would be extremely nice thing, but I have no idea of how to do such thing.

There's also no __FUNCTION__(or just doesn't work?) macro in EVC as far as I see, which is pretty unpleasant.

I believe there are more experienced people on subject of exception handling. What do you say on the topic? Any tricks are welcome :).
jaguard wrote:Maybe there's something wrong with my logging function, I'm openning and closing log file every time, because I think that if the program hangs, it won't log last messages, so the logging will be useless.
You could flush the buffer instead. I'm not sure how things work, but it likely waits for the buffer to fill up before a real write happens unless you flush it. Logging seems like the easiest way to narrow down your problem.
Yes, probably. But will it help?

Where are you people? :). Doesn't anyone logs anything?
I just use a log file when needed. re: exceptions I got them working when I moved to WM5. I used some online help stuff with downloads & it works fine. I can dig this out at the wekend if I get time.
Conan · 23 Mar 2006, 06:56 UTC — Sorry, I did not post twice ???
I just use a log file when needed. re: exceptions I got them working when I moved to WM5. I used some online help stuff with downloads & it works fine. I can dig this out at the wekend if I get time.
I'm presuming the double-post was an exception?
I used to use logging with this very effective piece of code:

STLogFile

briefly it can:

Code:
STLOG_WRITE
STLOG_MARKER
STLOG_WRITE_DATA
STLOG_LASTERROR
STLOG_PROFILE_BLOCK
STLOG_PROFILE_CHECKPOINT
joshbu [MSFT] · 28 Mar 2006, 18:03 UTC
It is possible to capture Windows CE thread callstacks, btw, with GetThreadCallStack.

http://msdn.microsoft.com/library/defau ... lStack.asp
refractor wrote:I'm presuming the double-post was an exception?

nah, it was just the log of the post. ;)
Unfortunately GetThreadCallStack would skip functions that does not use standart function prologs (i.e. don't store LR on stack, don't use exception handling, etc). For example tiny optimized functions would cause GetThreadCallStack to stop on them.
So it generally would be reliable only on debug builds of your program.