lucand
asked on
Catching system exceptions using C++ exception handling
Is that posible to catch system exceptions like "access violation" by using C++ exception handling? In that case what will be the thrown object that I can use into the catch() statement? I don't want to use the catch(...) because I need more information about the exception.
Thanks
Thanks
It depends. What operating system are you using?
>>It depends.
Actually, there are just 2 ways - SEH (Win32) or signals (all POSIX).
So, in code
(SEH)
__try {
// code here
} __except ( EXCEPTION_ACCESS_VIOLATION == GetExceptionCode()) {
throw new XcpMyAccVio ();
}
(POSIX)
void my_sigsegv_handler ( int) {
throw new XcpMyAccVio ();
}
signal ( SIGSEGV, my_sigsegv_handler);
Actually, there are just 2 ways - SEH (Win32) or signals (all POSIX).
So, in code
(SEH)
__try {
// code here
} __except ( EXCEPTION_ACCESS_VIOLATION
throw new XcpMyAccVio ();
}
(POSIX)
void my_sigsegv_handler ( int) {
throw new XcpMyAccVio ();
}
signal ( SIGSEGV, my_sigsegv_handler);
ASKER
I use WindowsNT,2000
I allready tryed signals and _set_se_translator() but not working into a multithreading program(any sugestions?).
SEH is not specifically designed for C++ and I get the following compilation error: "Cannot use __try in functions that require object unwinding"
I allready tryed signals and _set_se_translator() but not working into a multithreading program(any sugestions?).
SEH is not specifically designed for C++ and I get the following compilation error: "Cannot use __try in functions that require object unwinding"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SetUnhandledExceptionFilte r() is working with multithreading.
Thanks jkr!
Thanks jkr!
Hmmm, like I said originally, "It depends...."
The accepted solution is NOT C++ but rather a Windows-ism.
The accepted solution is NOT C++ but rather a Windows-ism.
Well, you could use the 'signal()' approach on Win32 also...
ASKER
Jhance you are right, that is not a pure C++ solution but it's working fine in Windows.
signal() is not working if the exception is into a child thread or if signal() is called from a DLL
Thanks
signal() is not working if the exception is into a child thread or if signal() is called from a DLL
Thanks