Click here to Skip to main content
15,891,905 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionException Handling in C++ Pin
theCPkid23-Jun-10 2:04
theCPkid23-Jun-10 2:04 
AnswerRe: Exception Handling in C++ Pin
Richard MacCutchan23-Jun-10 3:02
mveRichard MacCutchan23-Jun-10 3:02 
AnswerRe: Exception Handling in C++ Pin
Emilio Garavaglia23-Jun-10 4:47
Emilio Garavaglia23-Jun-10 4:47 
AnswerRe: Exception Handling in C++ Pin
Aescleal23-Jun-10 7:10
Aescleal23-Jun-10 7:10 
GeneralRe: Exception Handling in C++ Pin
VeganFanatic25-Jun-10 16:11
VeganFanatic25-Jun-10 16:11 
GeneralRe: Exception Handling in C++ Pin
Aescleal25-Jun-10 20:17
Aescleal25-Jun-10 20:17 
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt27-Jun-10 18:13
Stephen Hewitt27-Jun-10 18:13 
GeneralRe: Exception Handling in C++ Pin
Aescleal28-Jun-10 6:09
Aescleal28-Jun-10 6:09 
Which of the three uses do you disagree with? The first use (catch(...) at the end of main) is only when every other remedial action has failed and the program's going to crash anyway. If you have other base exceptions or exceptions that aren't derived from std::exception feel free to add catches for them at the top level.

Another type is where something throws in a destructor. You can't let exceptions come out of a destructor, std::terminate will end up being called in most cases. So the program's going to crash - you might as well handle it and tell the user that something's gone wrong then bail out cleanly.

A final example is where you don't know where you're throwing. If you have a C interface there's no guarentee that something on the other side knows what to do with it. So catch the exception and translate it to an error code - even if the error code is "Buggered if I know what went wrong in here mate..." which should be translated by the caller into stick up an error message and bail out of the program.

One final point - you shouldn't need to manually clean up resources in the face of an exception. We're talking C++ here and not Java (and even then you've got finally, not catch( ... ) ). The general idiom with C++ is to handle cleanup of resources using RAII, don't do it manually 'cause you're bound to miss something.

Cheers,

Ash
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt28-Jun-10 15:00
Stephen Hewitt28-Jun-10 15:00 
GeneralRe: Exception Handling in C++ Pin
theCPkid29-Jun-10 3:20
theCPkid29-Jun-10 3:20 
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt1-Jul-10 14:31
Stephen Hewitt1-Jul-10 14:31 
GeneralRe: Exception Handling in C++ Pin
theCPkid1-Jul-10 17:45
theCPkid1-Jul-10 17:45 
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt1-Jul-10 17:59
Stephen Hewitt1-Jul-10 17:59 
GeneralRe: Exception Handling in C++ Pin
theCPkid1-Jul-10 19:03
theCPkid1-Jul-10 19:03 
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt1-Jul-10 19:38
Stephen Hewitt1-Jul-10 19:38 
GeneralRe: Exception Handling in C++ Pin
Aescleal29-Jun-10 7:01
Aescleal29-Jun-10 7:01 
GeneralRe: Exception Handling in C++ Pin
Stephen Hewitt1-Jul-10 14:17
Stephen Hewitt1-Jul-10 14:17 
GeneralRe: Exception Handling in C++ Pin
theCPkid1-Jul-10 19:06
theCPkid1-Jul-10 19:06 
AnswerRe: Exception Handling in C++ [modified] Pin
theCPkid29-Jun-10 3:11
theCPkid29-Jun-10 3:11 
QuestionCRecordset old data problem Pin
eyalle23-Jun-10 0:29
eyalle23-Jun-10 0:29 
AnswerRe: CRecordset old data problem Pin
loyal ginger23-Jun-10 1:52
loyal ginger23-Jun-10 1:52 
GeneralRe: CRecordset old data problem Pin
eyalle23-Jun-10 2:14
eyalle23-Jun-10 2:14 
QuestionRe: CRecordset old data problem Pin
David Crow23-Jun-10 3:48
David Crow23-Jun-10 3:48 
QuestionPure virtual destructor ? Pin
krishna_CP23-Jun-10 0:17
krishna_CP23-Jun-10 0:17 
AnswerRe: Pure virtual destructor ? Pin
CPallini23-Jun-10 0:40
mveCPallini23-Jun-10 0:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.