473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Unreachable code error for exception handling code

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 this ? C++ exceptions are enabled
( /EHsc ).

Thanks.
SS


Nov 16 '05 #1
4 2789
SteadySteps wrote:
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 this ? C++
exceptions are enabled ( /EHsc ).


Can you narrow down a simple repro case that you can post here that produces
the warnings you're seeing, and the command-line options you're using to
compile it?

-cd
Nov 16 '05 #2
Hi

The project is an ATL Server project. I have now discovered that the
warnings occur only in the debug mode - so the compiler should not be
removing any code.

The switches used are:

/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS"
/D "_AFXDLL" /FD /EHsc /MDd /GR /Yu"stdafx.h" /Fp".\Debug/ProjectName.pch"
/Fo".\Debug/" /Fd".\Debug/" /W4 /nologo /c /ZI

The code is along these lines:

{
AFX_MANAGE_STATE(AfxGetAppModuleState())
try
{
m_dMemberSlope = newVal; //or some such simple assignments
}
catch( const _com_error& e )
{
ATLTRACE( _T("Error in line %d of %s: %s\n"), __LINE__, __FILE__,
e.ErrorMessage() );
ASSERT( false );
return e.Error();
}
catch( ... )
{
ATLTRACE( _T("Unknown error in line %d of %s\n"), __LINE__, __FILE__ );
ASSERT( false );
return E_FAIL;
}
return S_OK;
}

Thanks.
SS

"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:eS**************@TK2MSFTNGP12.phx.gbl...
SteadySteps wrote:
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 this ? C++
exceptions are enabled ( /EHsc ).
Can you narrow down a simple repro case that you can post here that

produces the warnings you're seeing, and the command-line options you're using to
compile it?

-cd



Nov 16 '05 #3
SteadySteps wrote:
Hi

The project is an ATL Server project. I have now discovered that the
warnings occur only in the debug mode - so the compiler should not be
removing any code.

The switches used are:

/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS"
/D "_AFXDLL" /FD /EHsc /MDd /GR /Yu"stdafx.h"
/Fp".\Debug/ProjectName.pch" /Fo".\Debug/" /Fd".\Debug/" /W4 /nologo
/c /ZI

The code is along these lines:
It looks like the catch blocks could simply be deleted (and the try) - the
code in the try can't possibly throw those exceptions, so the catch is
unreachable - that's why the warning is appearing. In a release build, the
compiler will completely optimize away the try/catch, so you might simply
want to use #pragma warning (disable:4702) to suppress the warning.

-cd

{
AFX_MANAGE_STATE(AfxGetAppModuleState())
try
{
m_dMemberSlope = newVal; //or some such simple assignments
}
catch( const _com_error& e )
{
ATLTRACE( _T("Error in line %d of %s: %s\n"), __LINE__, __FILE__,
e.ErrorMessage() );
ASSERT( false );
return e.Error();
}
catch( ... )
{
ATLTRACE( _T("Unknown error in line %d of %s\n"), __LINE__,
__FILE__ ); ASSERT( false );
return E_FAIL;
}
return S_OK;
}

Thanks.
SS

"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:eS**************@TK2MSFTNGP12.phx.gbl...
SteadySteps wrote:
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 this ? C++
exceptions are enabled ( /EHsc ).


Can you narrow down a simple repro case that you can post here that
produces the warnings you're seeing, and the command-line options
you're using to compile it?

-cd

Nov 16 '05 #4
Yes that seems to be the case. The exception code is generally always added
in a kind of 'company' policy.

Thanks for you help.
"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
SteadySteps wrote:
Hi

The project is an ATL Server project. I have now discovered that the
warnings occur only in the debug mode - so the compiler should not be
removing any code.

The switches used are:

/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS"
/D "_AFXDLL" /FD /EHsc /MDd /GR /Yu"stdafx.h"
/Fp".\Debug/ProjectName.pch" /Fo".\Debug/" /Fd".\Debug/" /W4 /nologo
/c /ZI

The code is along these lines:
It looks like the catch blocks could simply be deleted (and the try) - the
code in the try can't possibly throw those exceptions, so the catch is
unreachable - that's why the warning is appearing. In a release build,

the compiler will completely optimize away the try/catch, so you might simply
want to use #pragma warning (disable:4702) to suppress the warning.

-cd

{
AFX_MANAGE_STATE(AfxGetAppModuleState())
try
{
m_dMemberSlope = newVal; //or some such simple assignments
}
catch( const _com_error& e )
{
ATLTRACE( _T("Error in line %d of %s: %s\n"), __LINE__, __FILE__,
e.ErrorMessage() );
ASSERT( false );
return e.Error();
}
catch( ... )
{
ATLTRACE( _T("Unknown error in line %d of %s\n"), __LINE__,
__FILE__ ); ASSERT( false );
return E_FAIL;
}
return S_OK;
}

Thanks.
SS

"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:eS**************@TK2MSFTNGP12.phx.gbl...
SteadySteps wrote:
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 this ? C++
exceptions are enabled ( /EHsc ).

Can you narrow down a simple repro case that you can post here that
produces the warnings you're seeing, and the command-line options
you're using to compile it?

-cd


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
1
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
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;
4
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
3
by: dhussong | last post by:
I'm trying to implement a generic exception handling routine that will write information to a text file at the time the exception occurred. I am using the Microsoft Application Block for Exception...
41
by: Jordan | last post by:
While writing some code, I realized I had never developed a consistent pattern for checking errors from a method. I have two styles I jump back and forth between, but I'm wondering which is...
4
by: Gernot Frisch | last post by:
I get informed that parts of my code cannot be reached. Did I do something wrong? try { if (login(progstring) > 0) { return 1; // OK } }
4
by: John Wright | last post by:
I need some good ideas or references for robust error handling in VB.NET. I am using try catch but find myself using the generic exception handler. I would like to get more precise error handling...
1
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.