Click here to Skip to main content
15,920,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
Sorry, most of the open source code I use comes from the Linux community and they're not great fans of C++. As a few guidelines:

You generally don't handle exceptions that often. Usually an exception means that something has gone horribly wrong and it's game over folks, let's just clean up and hope a restart gives a better result.

So generally you'd use an exception handler around main() for a console application and that's about it:

int main()
try
{
    // Much good stuff in here...
}
catch( std::exception &e )
{
    std::cout << "Something went wrong: " << e.what() << std::endl;
}
catch( ... )
{
    std::cout << "Something went wrong, no idea what!" << std::endl;
}


If you're writing a shared library or DLL with a C interface you'll want to catch exceptions before exiting a cdecl function. C (and other programming languages) don't know about C++ exceptions so it's a bit rude to through one at them.

The same goes for callbacks which go through any third party libraries (e.g. windows procedures in Windows). They may or may not have the same exception strategy and may not be able to handle them.

Cheers,

Ash
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 
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 
AnswerRe: Pure virtual destructor ? Pin
Chris Losinger23-Jun-10 1:30
professionalChris Losinger23-Jun-10 1:30 
AnswerRe: Pure virtual destructor ? Pin
Aescleal23-Jun-10 6:52
Aescleal23-Jun-10 6:52 

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.