Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling in linux

I am porting a Windows program on Linux. My program uses the Windows structured exception handling (SEH). Linux does not support structured exception handling, however it provides signal handling. We can override signal to develop SEH like paradigm.

Once you are able to filter the exception Windows provides three alternatives execution control flows:

1) EXCEPTION_EXECUTE_HANDLER : Execute handler 2) EXCEPTION_CONTINUE_SEARCH : Forward the exception to next block (if not exist then to OS) 3) EXCEPTION_CONTINUE_EXECUTION : Continue exception from the instruction where interrupt has occured.

How can I achieve this control flows in Linux. In Linux once you handle the signal, program starts execution from where it has been interrupted. How to develope continue_search and execute_handler paradigms?

Thanks in advance

like image 829
Utkarsh Avatar asked Aug 30 '11 13:08

Utkarsh


1 Answers

There is no easy way to do what you want here in C++. Your tools are the standard C++ exception mechanism, and sigaction. A sigaction handler can return control to where it left off. It can throw, though there has been controversy about the safety of this. Some would say that it has to set an atomic variable and return. (The problem being that the compiler sees no possibility of a throw and so doesn't prepare for it.)

If you are working in C, you have additional complex options involving sigsetjmp, which is more or less goto on steroids, risks and all.

Since you haven't specified a language, or what exceptional condition you are trying to deal with, it's not practical to offer a more specific recipe.

like image 77
bmargulies Avatar answered Sep 20 '22 21:09

bmargulies