|
From: Brian D. <br...@de...> - 2007-04-09 07:25:49
|
anandnld wrote: > Im using MinGw gcc compiler. In my program im using 3 files. > 1. Header file > 2. Definition file for the functions in header file > 3. Accessing those methods in 3rd file > > While accessing the methods from 2nd file, some memory exceptions are > occuring. im not able to catch those exceptions. Can any one help in > that.... > [...] > while accessing the method in 3 file memory reference error occured as "The > instruction at "0x7c812009" referenced momory at "0x00000000". The memory > could not be "read". while running and control exits there itself. How to > exception from my 3rd file. NOT TO CATCH THE EXCEPTION IN 2nd FILE. This is almost certainly a bug in your getValue function, that's doing something it shouldn't (in this case dereferencing a NULL pointer.) You should fix that, and not try to catch the exception. You may be getting confused about the different kind of exceptions. C++ provides exceptions as part of the langauge, in the form of try/catch. This is a *language* thing, completely independant of the operating system, implemented entirely by the compiler. The only exceptions you will catch here are ones that your C++ code or the STL explicitly throws. You won't get anything from the operating system. The operating system itself has a completely separate and unrelated kind of exception, called SEH (structed exception handling.) This is a *language-indedepent* thing provided by the OS and can be utilized by any kind of code, C, C++, assembler, whatever. This is where you catch invalid access faults and Ctrl-C events and so on. The Microsoft toolchain implements __try/__except/__finally in order to directly access these SEH functions from C or C++. Note that these are entirely different from C++ exceptions! However the MS toolchain implements C++ exceptions using SEH, so they are related; but that's an implementation detail. The GNU toolchain does not (yet) speak SEH, sadly. It implements C++ exceptions using either setjmp/longjmp (SJLJ) or Dwarf-2, sometimes called no-cost exception handling because unwinding is done by looking at tables stored in the debug information on how to unwind the frame, which happens only when an exception occurs. However, since SEH is an operating system-provided feature, you can still make use of some of its features even without compiler support. This is all documented on MSDN, see <http://msdn2.microsoft.com/en-us/library/ms680657.aspx>. In your case, the popup error message that you are seeing is a result of the system's default unhandled exception filter stepping in to handle the fault. You can use SetUnhandledExceptionFilter() to install your own exception handler and deal with the fault. Brian |