uncaught exception handler?

Is it possible to write a custom exception handler for uncaught exceptions? I have this code:
1
2
3
4
5
6
7
#include <exception>
using namespace std;

class exception:public myexception
{
// code here
};

Now if I throw myexception and it's not catched, program displays a dialog box (for GUI app ) or some text saying that "terminate called after throwing an istance of..." or something similar. So maybe it is possible to write a custom default exception handler which would allow to continue execution of my program?

Thanks for help.
Yeah. It's called catch (...). The runtime puts that around your main() to catch everything your crappy code throws. Due to the way exceptions work, you can only resume execution at the stack frame that caught the exception. All the state in the frames between the thrower and the catcher was destroyed in the process. In other words, you can't do this:
1
2
3
4
5
6
7
int main(){
    try{
        my_main();
    }catch (...){
        magically_restore_call_stack();
    }
}

If you want to resume execution, you have to catch exceptions at the point you want to resume.
Last edited on
OK, thanks.
Topic archived. No new replies allowed.