By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 1,990 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 error for exception handling code

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.