Click here to Skip to main content
15,922,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Read an executable and write the data to a file. Pin
harold aptroot23-Jun-10 5:31
harold aptroot23-Jun-10 5:31 
GeneralRe: Read an executable and write the data to a file. Pin
Not Active23-Jun-10 6:00
mentorNot Active23-Jun-10 6:00 
GeneralRe: Read an executable and write the data to a file. Pin
harold aptroot23-Jun-10 6:15
harold aptroot23-Jun-10 6:15 
AnswerRe: Read an executable and write the data to a file. Pin
Code-o-mat23-Jun-10 5:28
Code-o-mat23-Jun-10 5:28 
GeneralRe: Read an executable and write the data to a file. Pin
ALLERSLIT23-Jun-10 5:46
ALLERSLIT23-Jun-10 5:46 
GeneralRe: Read an executable and write the data to a file. Pin
Code-o-mat23-Jun-10 6:38
Code-o-mat23-Jun-10 6:38 
AnswerRe: Read an executable and write the data to a file. Pin
ant-damage23-Jun-10 5:48
ant-damage23-Jun-10 5:48 
AnswerRe: Read an executable and write the data to a file. Pin
El Corazon23-Jun-10 5:58
El Corazon23-Jun-10 5:58 
AnswerRe: Read an executable and write the data to a file. Pin
Richard MacCutchan23-Jun-10 6:35
mveRichard MacCutchan23-Jun-10 6:35 
QuestionArray Pin
Nikesh Jagtap23-Jun-10 2:11
Nikesh Jagtap23-Jun-10 2:11 
AnswerRe: Array Pin
CPallini23-Jun-10 2:18
mveCPallini23-Jun-10 2:18 
AnswerRe: Array Pin
Sakhalean23-Jun-10 2:18
Sakhalean23-Jun-10 2:18 
AnswerRe: Array PinPopular
Maximilien23-Jun-10 2:31
Maximilien23-Jun-10 2:31 
GeneralRe: Array Pin
Richard MacCutchan23-Jun-10 3:00
mveRichard MacCutchan23-Jun-10 3:00 
GeneralRe: Array Pin
Maximilien23-Jun-10 3:56
Maximilien23-Jun-10 3:56 
AnswerRe: Array Pin
Chris Losinger23-Jun-10 3:58
professionalChris Losinger23-Jun-10 3:58 
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 

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.