[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Nedd a tutorial on exception handling in C++

Posted on 2004-11-04
Medium Priority
Last Modified: 2006-11-17
I haven't done much try - catch type of exception handling in c++ so I need to learn it.  For example is there a way to just trap any exception and have the code do something if that happens, or do I always have to actually specify what the problem is?
So basicaly, can I somehow do this:

 //my code - anything

catch (anyProblem)  //any error that would make the app crash

I am also looking for a tutorial and/or good book on this.

Any help is appreciated,

Question by:axnst2
  • 2
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 12494919
You'd use an ellipsis in the 'catch' statement, e.g.:

//my code - anything

catch (...)  //any error that would make the app crash

The problem with this approach is that the handler cannot do much except stating "something happened" as you cannot find out of what type the exception was that got caught. Also, you cannot catch OS-specific exceptions (like SEH or signals) with that. A tuturial can be found e.g. at http://www.cplusplus.com/doc/tutorial/tut5-3.html or http://cplus.about.com/library/weekly/aa122202a.htm


Author Comment

ID: 12495116
Thanks this is great.  What do I put in () at catch() for it to just catch any problem instead of crashing?
LVL 86

Expert Comment

ID: 12495504
What OS are you on?

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question