LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-24-2011, 06:49 PM   #1
cyker
LQ Newbie
 
Registered: Jul 2010
Location: Beijing
Distribution: Arch
Posts: 9

Rep: Reputation: 0
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.
 
Old 01-24-2011, 07:06 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,246

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
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...
 
Old 01-25-2011, 06:04 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,057
Blog Entries: 1

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the best IDE for system level programming in Linux using C? balajesankar Programming 1 05-24-2010 11:45 PM
LXer: How to catch Linux system intruders LXer Syndicated Linux News 0 09-20-2008 03:40 PM
wxPython Catch System Shutdown mp035 Programming 2 02-10-2008 04:04 PM


All times are GMT -5. The time now is 08:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration