LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to catch system-level exceptions in Linux (https://www.linuxquestions.org/questions/programming-9/how-to-catch-system-level-exceptions-in-linux-858446/)

cyker 01-24-2011 06:49 PM

How to catch system-level exceptions in Linux
 
The following C++ program doesn't catch the exception:

Code:

#include <iostream>
using namespace std;
 
int main()
{
    try
    {
        int i = 0;
        int j = 1;
        int k = j/i;
    }
    catch(...)
    {
        cout << "exception" << endl;
    }
    return 0;
}

After compiled and run, it gives

Floating Point Exception

rather than

exception

Signals can be used to handle this divide-by-zero exception, but will that work for all other system-level exceptions? I just want a simple method to make catch() work. Thanks.

chrism01 01-24-2011 07:06 PM

I'd suggest using the Report button to ask the Mods to move this to the Programming forum, although you may well get an answer here...

onebuck 01-25-2011 06:04 AM

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 03:32 AM.