473,587 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "unreachabl e code". How can I correct this ? C++ exceptions are enabled
( /EHsc ).

Thanks.
SS


Nov 16 '05 #1
4 2825
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 "unreachabl e 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_STAT E(AfxGetAppModu leState())
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******@nospa m.mvps.org> wrote in message
news:eS******** ******@TK2MSFTN GP12.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 "unreachabl e 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_STAT E(AfxGetAppModu leState())
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******@nospa m.mvps.org> wrote in message
news:eS******** ******@TK2MSFTN GP12.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 "unreachabl e 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******@nospa m.mvps.org> wrote in message
news:OF******** ******@TK2MSFTN GP09.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_STAT E(AfxGetAppModu leState())
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******@nospa m.mvps.org> wrote in message
news:eS******** ******@TK2MSFTN GP12.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 "unreachabl e 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
2857
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 return code (not generating error/exception) so it is more compatible with other programming language.
1
384
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 this ? C++ exceptions are enabled ( /EHsc ). Thanks. SS
2
1983
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
1833
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
1627
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 Handling to write to a text file. This is working great plus I get the call stack which is an added bonus. What I really want to get is the value of parameters and variables in each method in the call stack at the time of the exception. I know I...
41
1905
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 better. Scenario: * In method that returns success/fail * Call method that also returns success/fail * Need to check return state and continue or exit outer method I personally think Case 1 looks a little cleaner but it breaks more
4
6970
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
1964
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 so I can take appropriate action and display user friendly error messages back to the client. The problem I am getting is determining which error types can be thrown for each function/sub and handling them. Is there a way to determine all the...
1
2503
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 possibly be done after the return statement hence the break statement will not and can ever be reached? switch (suffix) { case 1: return "<sup>st</sup>"; break;
0
7927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8220
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8222
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5723
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.