473,509 Members | 7,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unreachable code?

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
4 6963
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
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
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
>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1634
by: Tom Anderson | last post by:
Evening all, Here's a brief chat with the interpretator: Python 2.4.1 (#2, Mar 31 2005, 00:05:10) on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def...
1
315
by: Kepler | last post by:
I have a situation where I need to use a Using statement that creates some records in a database. After that completes, if it completes, I need to do some file creation. Any code I'm putting...
4
2810
by: SteadySteps | last post by:
Hi I migrated a project which compiles correctly on VC 6.0 to VS 2002. However now all I get several warning that all the statements within catch blocks are "unreachable code". How can I correct...
2
1973
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
0
1192
by: michael | last post by:
I am migrating C++ unmanaged to managed VC 7.1. I continue to have problems with try catch blocks through-out my code. The compile tells me the the code is unreachable C2407 at the catch portion of...
6
27516
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
1
1708
by: tam | last post by:
when i am using session variable i found one error that unreachable core error. how to rectify this error
1
2498
by: HillBilly | last post by:
What does that error mean and why would each break statement be marked as unreachable? It implies the return will --always-- return some --thing-- if even null and no further processing can...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.