// JP opened flex table

Click to See Complete Forum and Search --> : win32 dll try-catch


ArtZ
November 24th, 2001, 12:05 AM
Why does the compiler flag the line XX below as "warning C4702: unreachable code".
Also, what is different from the compiler's view about this try - catch block vs. the previous ones below? The compiler does have - Enable exception handling checked under C++ language. Using MSVC 6.0. The try has an assignment statement wTool = 0. Just don't see why or where the limitation is, help! Also, I do not have this problem when compiling a DEBUG version of a Win32 DLL just a non-debug version. Again, this is during compile, not linking.

Thank you,

void SEHFunc();
char szTmp[64];

int mainxx()
{
int wTool;

try
{
SEHFunc();
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception.");
}
try
{
SEHFunc();
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception.");
}

try {
wTool = 0;
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception."); // Line XX
}

return 0;
}
void SEHFunc()
{
__try
{
int x, y = 0;
x = 5 / y;
}
__finally
{
sprintf(szTmp, "In finally.");
}
}

nikb
December 2nd, 2001, 12:33 AM
Hello,

What compiler did you try to compile this with? I used VC++ 6.0 and it worked fine:In reply to:

C:\>cl -GX test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:test.exe
test.obj

C:\>




I added #include <stdio.h> to the top of the file, and renamed mainxx in your code to main; I also gave it the 'right' prototype: int main(int,char **) The code follows:#include <stdio.h>

void SEHFunc();
char szTmp[64];

int main(int,char **)
{
int wTool;

try
{
SEHFunc();
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception.");
}

try
{
SEHFunc();
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception.");
}

try {
wTool = 0;
}
catch( ... )
{
sprintf(szTmp,"Caught a C exception."); // Line XX
}

return 0;
}

void SEHFunc()
{
__try
{
int x, y = 0;
x = 5 / y;
}
__finally
{
sprintf(szTmp, "In finally.");
}
}



You need to be more specific about what compiler you used, whether this is part of a larger program, etc.

-n

SigEpUCI
December 5th, 2001, 06:08 PM
Because that line represents a primitive assignment, which can not generate an exception, hence that catch block will never be exercised.

viva la NSX

//JP added flex table