By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

unreachable code?

P: n/a
I get informed that parts of my code cannot be reached. Did I do
something wrong?

try
{
if (login(progstring) > 0)
{
return 1; // OK
}
}
catch(int) // No hardlock
{
try
{
logout(NULL); // unreachable code
}
catch(int)
{;}
g_Version = MAX_VERSION; // unreachable code
}


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Apr 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Gernot Frisch wrote:
I get informed that parts of my code cannot be reached. Did I do
something wrong?

try
{
if (login(progstring) > 0)
{
return 1; // OK
}
}
catch(int) // No hardlock
{
try
{
logout(NULL); // unreachable code
}
catch(int)
{;}
g_Version = MAX_VERSION; // unreachable code
}


Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 27 '06 #2

P: n/a
Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code.

OK. I use VC++7.1. My compiler flags seem OK:
/Od /FD /EHsc /RTC1 /MTd /GS /c /ZI /Gd /TP

Here's the code (uncalled stuf removed)

extern "C"
{
int login( const char *);
int logout(const char *);
void lib_pexit(int);
SetFunctions(void*);
}

#define MAX_VERSION 2002
int g_Version = MAX_VERSION;

// get's called on error
void lib_pexit( int ErrorCode )
{
throw (1); // C4297 unexpected exception raised
}
int CheckFeature(const char* progstring, double version)
{
SetFunctions((void*)&lib_pexit); // register "lib_pexit" function

for (int nVersion = (int)version; nVersion<=tm.wYear+3; nVersion++)
{
g_Version = nVersion;
try
{
if (login(progstring) > 0)
{
g_Version = MAX_VERSION;
return 1; // OK
}
}
catch(int) // no hardlock
{
try
{
logout(NULL);
}
catch(int)
{;}
g_Version = MAX_VERSION; // C4702 unreachable code
}
}
g_Version = MAX_VERSION; // C4702 unreachable code
return 0;
}



Apr 27 '06 #3

P: n/a
Gernot Frisch wrote:
Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code.


OK. I use VC++7.1. My compiler flags seem OK:
/Od /FD /EHsc /RTC1 /MTd /GS /c /ZI /Gd /TP

Here's the code (uncalled stuf removed)

extern "C"
{
int login( const char *);
int logout(const char *);
void lib_pexit(int);
SetFunctions(void*);
}

#define MAX_VERSION 2002
int g_Version = MAX_VERSION;

// get's called on error
void lib_pexit( int ErrorCode )
{
throw (1); // C4297 unexpected exception raised
}


I would assume that "C" functions must not throw, so lib_pexit is not expected
to throw and CheckFeature is not prepared to catch the exception raised by a
"C"-function (->unreachable code)
hth
Klaus

Apr 27 '06 #4

P: n/a
>
Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code. OK. I use VC++7.1. My compiler flags seem OK:
/Od /FD /EHsc /RTC1 /MTd /GS /c /ZI /Gd /TP

I would assume that "C" functions must not throw, so lib_pexit is not
expected to throw and CheckFeature is not prepared to catch the
exception raised by a "C"-function (->unreachable code)


/EHc extern "C" defaults to nothrow.
Apr 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.