LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,923
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration