Click here to Skip to main content
15,915,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Why is this C++ Exception unhandled ? Pin
Defenestration25-Apr-06 15:41
Defenestration25-Apr-06 15:41 
Thanks for the info Steve. I'm haven't really used exceptions before, so I'm trying to understand when they should be used and when they shouldn't be used.

However, it did not completely solve the problem. When using the /EHa switch, the exception seems to get caught, but the catch{} handler is not called (ie. the message is not printed out). I tried using Microsoft own example below, but again the message "Caught an exception in...." is not displayed. Why isn't the catch(...){} block being executed ?

Also, since hardware exceptions should not be caught in standard C++, what would be the correct way to handle such an exception (eg. divide-by-zero) in a standards compliant way (eg. using if (0 == y) checks ?) ?

// compiler_options_EHA.cpp<br />
// compile with: /EHa<br />
#include <iostream><br />
#include <excpt.h><br />
using namespace std;<br />
<br />
void fail() {   // generates SE and attempts to catch it using catch(...)<br />
   try {<br />
      int i = 0, j = 1;<br />
      j /= i;   // This will throw a SE (divide by zero).<br />
   }<br />
   catch(...) {   // catch block will only be executed under /EHa<br />
      cout<<"Caught an exception in catch(...)."<<endl;<br />
   }<br />
}<br />
<br />
int main() {<br />
   __try {<br />
      fail(); <br />
   }<br />
<br />
   // __except will only catch an exception here<br />
   __except(EXCEPTION_EXECUTE_HANDLER) {   <br />
   // if the exception was not caught by the catch(...) inside fail()<br />
      cout << "An exception was caught in __except." << endl;<br />
   }<br />
}

Questionvalidating user/pass inputs Pin
Kharfax25-Apr-06 5:35
Kharfax25-Apr-06 5:35 
QuestionProject for class Pin
JarethAshaer25-Apr-06 5:25
JarethAshaer25-Apr-06 5:25 
AnswerRe: Project for class Pin
David Crow25-Apr-06 6:21
David Crow25-Apr-06 6:21 
AnswerRe: Project for class Pin
Bob Flynn25-Apr-06 6:48
Bob Flynn25-Apr-06 6:48 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:15
JarethAshaer25-Apr-06 7:15 
GeneralRe: Project for class Pin
Bob Flynn25-Apr-06 7:23
Bob Flynn25-Apr-06 7:23 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:27
JarethAshaer25-Apr-06 7:27 
GeneralRe: Project for class Pin
Bob Flynn25-Apr-06 7:40
Bob Flynn25-Apr-06 7:40 
GeneralRe: Project for class Pin
JarethAshaer25-Apr-06 7:52
JarethAshaer25-Apr-06 7:52 
Questionwhat are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 5:12
rotorcli25-Apr-06 5:12 
AnswerRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
Chris Losinger25-Apr-06 5:16
professionalChris Losinger25-Apr-06 5:16 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 5:46
rotorcli25-Apr-06 5:46 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
Chris Losinger25-Apr-06 6:16
professionalChris Losinger25-Apr-06 6:16 
GeneralRe: what are the differences between .dll and .lib file?eg. gdi32.dll and gdi32.lib Pin
rotorcli25-Apr-06 6:27
rotorcli25-Apr-06 6:27 
QuestionProblem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:06
Defenestration25-Apr-06 5:06 
AnswerRe: Problem compiling with VC++ 2005 Pin
Cedric Moonen25-Apr-06 5:10
Cedric Moonen25-Apr-06 5:10 
GeneralRe: Problem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:21
Defenestration25-Apr-06 5:21 
GeneralRe: Problem compiling with VC++ 2005 Pin
Defenestration25-Apr-06 5:26
Defenestration25-Apr-06 5:26 
QuestionAFX_INCLUDE() Pin
longdt925-Apr-06 3:54
longdt925-Apr-06 3:54 
AnswerRe: AFX_INCLUDE() Pin
YaronNir25-Apr-06 4:00
YaronNir25-Apr-06 4:00 
AnswerRe: AFX_INCLUDE() Pin
David Crow25-Apr-06 4:01
David Crow25-Apr-06 4:01 
GeneralRe: AFX_INCLUDE() Pin
YaronNir25-Apr-06 4:06
YaronNir25-Apr-06 4:06 
GeneralRe: AFX_INCLUDE() Pin
David Crow25-Apr-06 4:12
David Crow25-Apr-06 4:12 
QuestionHow to read words from a notepad application in VC++ program Pin
lekshmipriya25-Apr-06 3:39
lekshmipriya25-Apr-06 3:39 

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.