warning C4702: unreachable code in Visual Studio .NET 2002, even with /EHac 
Author Message
 warning C4702: unreachable code in Visual Studio .NET 2002, even with /EHac

Hi,

I have a C++ method which contains the following code, and when I compile it
with Visual Studio .NET 2002 (VC7), even in debug mode, I get "warning
C4702: unreachable code" on the catch() line.  I am compiling with asynch
exceptions (/EHac), so all functions, regardless of specification, should
assume and exception specification of throw(...) (which means it could throw
anything.)  And, in fact, CDaoRecordset::Update() has no exception
specification, and it CAN throw a CDaoException - even the MSDN
documentation says it can.  The same problem happens for
CDaoRecordset::Edit(), as well as CDaoWorkspace::BeginTrans(),
::CommitTrans(), and ::Rollback().

All of this worked fine in VC 6 without warnings.  I have two concerns:

1) since the compiler thinks the exceptions won't be thrown, is the handling
code being compiled out?

2) is this warning bogus or not?  that is, can I safely disable this warning
for this call?  I don't want to disable it globally as this warning has
already found some real bugs for us.

for (;;)

{

    try

    {

        CDaoRecordset::Update();

        break;

    }

   catch (CDaoException *e)

  {

        if (m_nRetries == 0)

        {

e->m_pErrorInfo->m_strDescription += " foo";

            throw;

        }

        switch (e->m_pErrorInfo->m_lErrorCode)

        {

            //snip

        }

   }

Quote:
}

-Thanks!


Mon, 27 Jun 2005 22:00:49 GMT  
 warning C4702: unreachable code in Visual Studio .NET 2002, even with /EHac
Hi A,

Quote:
> 1) since the compiler thinks the exceptions won't be thrown, is the
handling
> code being compiled out?

The warning means the compiler thinks the EH handler code is unnecessary and
will remove it if optimizations are used.

Quote:
> 2) is this warning bogus or not?  that is, can I safely disable this
warning
> for this call?  I don't want to disable it globally as this warning has
> already found some real bugs for us.

The warning is not bogus, if you are seeing it then the compiler will not
emit code to handle the exception. To see for yourself, check the .cod file
(compile with /FAsc.) For some reason, in your program, the compiler
believes that CDaoRecordset::Update will not throw an exception. I have
attempted to reproduce this behavior, but cannot. We will need a more
complete example before we can discover the problem.

--
Eric Christoffersen

Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.



Wed, 29 Jun 2005 03:45:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. False C4702 warnings for "unreachable code"

2. warning C4702: unreachable code

3. Warning C4702 (unreachable code) in xtree

4. C4702 "unreachable code" under release compilation

5. Mappoint 2002 and C# in visual studio.net

6. Can you disable specific warnings or change warning level per file in Visual Studio.NET

7. e: *HELP* After install Visual studio .Net, the Visual Studio Enterprise 6.0 stops working

8. *HELP* After install Visual studio .Net, the Visual Studio Enterprise 6.0 stops working

9. *HELP* After install Visual studio .Net, the Visual Studio Enterprise 6.0 stops working

10. MAKEFILE and Visual Studio 2002

11. Using Embedded Visual Studio with PPC 2002?????

12. CanTrial Version of Visual Studio .NET 2003 Co-exist with Visual C++.NET 2002?

 

 
Powered by phpBB® Forum Software