473,396 Members | 1,676 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,396 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 2796
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.