Sign in to follow this  
GameMasterXL

Exception Handler, getting error offset

Recommended Posts

I am building an exception handler for my parser that will hopefully sifer out any bad errors. I am wanting though to display the offset of were the error occured from the .exe file. Is there a way off getting the error offset? I also tried google but nothing :(. [Edited by - GameMasterXL on July 2, 2005 5:48:32 AM]

Share this post


Link to post
Share on other sites
I am not sure what you mean by offset, but you can use the __FILE__, __FUNCTION__ and __LINE__ macros to display which file, function and line the error occured on.

Share this post


Link to post
Share on other sites
The offset in the .exe file of were the exception occured, like ox06E2 or something. Does anyone know how this can be achieved? i am trying to display the message layout like so if the message is a known error then like this [error message:][@ offset][at line number]. So the user knows were in the .exe file the exception occured. Like Internal program error, the program needs to close: @ 0x053E2 at line 20. By anychance does the _line macro get the line of were the error occured in the .exe?

Share this post


Link to post
Share on other sites
The __LINE__ marcor gives the line of the source file; an EXE has no lines because it is a binary file. The __FILE__ gives you the source filename. I've always wondered why anyone would want to know the actual offset in the EXE file -- to me it has not much meaning as I have no understanding of the interals of EXE's; I think most programmers will be more interested in the line/file/function than the binary offset.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Well the binary offset will pin point the piece of memory it is in in the file. If i am right, but it shows the location, like hacking halos .map files for modding them you had to read in the offsets and swap them which pointed to different locations of the file. I was thinking like the offset to pin point just for a test the part of the file were the error occured like you said you can't get the line number from the .exe file since it is in binary. So i don't think the line macro will work unless i hog my program with it :) if it does someone pleas explain how i can possibly use it. If anyone knows how this can be achieved pleas explain how, surly someone her has done one 'anyone' o_O. Well if this is not possible can someone explain of what exceptions i could catch if one occures in my parser? i got one for maby an empty script file, STD errors (is this correct for creating an exception), abnormal program termination overloading the terminate function, internal buffer-overflows/underflows ect. Is there anymore i could check?

Share this post


Link to post
Share on other sites
What OS and what kind of exception handling?

In Windows, for structured exception handling (i.e. __try/__finally, not C++ try/catch) you call GetExceptionInformation in your exception filter to get all kinds of info. Correctly interpreting all this information isn't really for beginners though so be sure you know what you're doing.

For C++ try/catch there is no portable way other than to manually embed the necessary info in your exception object at the time of the throw. The __LINE__ and __FILE__ stuff people are talking about above are examples of that sort of info.

Share this post


Link to post
Share on other sites
I am using windows xp and C++. Can i not do some math on the _line macro to give me the intial offset? or if not how do i impliment the line Macro?

Share this post


Link to post
Share on other sites
Quote:
Original post by garyfletcher
__LINE__ will probably NOT give you the line that the error occured on..unless you test EVERY line of code that is.


I pass __LINE__ in as a parameter into most of my exceptions, so that, even though I can't tell where the call that borked things came from (I can do that by doing a call-stack trace though, hurray for building in lots of debugging hooks early on!), I can at least tell where the exception originated from.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this