Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:43:24+00:00 2026-05-16T11:43:24+00:00

MSVC 10 and MSVC 9 are both generating a level 4 warning message when

  • 0

MSVC 10 and MSVC 9 are both generating a level 4 warning message when compiling my exception framework, although the behavior of the program seems correct. The exception framework is rather large & complex, but I have managed to boil it down to its essence. This is a complete program you can compile & run in VS10

#include <cstdlib>
#include <stdexcept>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;

    namespace ex
    {
        class generic_error : virtual public std::exception
        {
        public:
            generic_error(int thread_id) : thread_id_(thread_id) {}
            const char* what() const throw()
            {
                static std::string msg;
                stringstream ss;
                ss << "generic error in thread #" << thread_id_;
                msg = ss.str();
                return msg.c_str();
            }
            int thread_id_;
        };

        template<class EX>
        class traced_error : virtual public std::exception, virtual public EX
        {
        public:
            traced_error(int line, const EX& ex):   EX(ex), line_(line) { }
            const char* what() const throw()
            {
                static std::string msg;
                stringstream ss;
                ss << "traced error on line " << line_ << " : '" << EX::what() << "'";
                msg = ss.str();
                return msg.c_str();
            }
            int line_;
        };

        template<class EX> traced_error<EX> make_traced_error(int line, const EX& ex)
        {
            return traced_error<EX>(line, ex);
        }
}

    int main()
    {
        try
        {
            throw ex::make_traced_error(__LINE__, ex::generic_error(234));
        }
        catch( const ex::generic_error& gex )
        {
            cout << "gex = " << gex.what();
            return 2;
        }
        catch( const exception& ex )
        {
            cout << ex.what();
            return 1;
        }
    }

When compiling the line throw ex::make_traced_error(__LINE__, ex::generic_error(234)); the compiler emits:

1>hacks_vs10.cpp(51): warning C4673: throwing 'ex::traced_error<EX>' the following types will not be considered at the catch site
1>          with
1>          [
1>              EX=ex::generic_error
1>          ]

One of the goals of this exception library is to append source file information to every thrown exception. I use a macro that evaluates to throw ex::make_traced_error(__FILE_, __LINE__, ex);, but that was not necessary to replicate the compiler warning.

make_traced_error instantiates a template exception class, the template parameter for which is the exception being thrown, in this case generic_error. Obviously if I simply throw a plain generic_error the compiler is happy, but this is not what I want to do.

What is the cause and effect of this warning? Is the compiler wrong, or is my code? I should note a couple things here.

First, when I execute this code it does what I expect it to do. The generic_error catch block is called rather than the general exception block, and the output of the program is:

gex = traced error on line 51 :

Second, when I compile this code with the Comeau online compiler it compiles without error or warning, suggesting to me that my code is Standards-compliant and legal C++. Correct assumption?

‘generic error in thread #234’

Finally, I have seen the MS knowledge base article about this warning. But MS’s explanation was fully unsatisfactory (it did not explain the cause of the warning), and their resolution is unacceptable — they say that I should just throw a straight generic_error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:43:25+00:00Added an answer on May 16, 2026 at 11:43 am

    The issue is indirectly about the multiple virtual inheritance from std::exception. The compiler gets confused because of it, but forgets to tell you why. :-/

    James McNellis is right: the compiler promises to mention a type, but it doesn’t. Try without the template:

    #include <stdexcept>
    
    class Base: virtual public std::exception {};
    class Derv: public Base, virtual public std::exception {};
    
    int main()
    {
      try {
        throw Derv();
      } catch (const Base &) {
        return 2;
      } catch (...) {
        return 1;
      }
    }
    

    When compiled with level 4 warnings, this says nothing more than:

    warning C4673: throwing ‘Derv’ the following types will not be considered at the catch site

    I see the value of warnings. But apparently level 4 is buggy in this case. As all works as expected you could just silence the compiler:

    #pragma warning(disable: 4673)
    

    I guess you could report this case as a bug to Microsoft. The compiler should state the type and what the problem is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is generating warning C6284 when compiled with /analyze on MSVC 2008
Seems all compilers can deal with both c and c++,like gcc ,msvc... Is it
I am trying to build a program using the command scons compiler = msvc.
So I have a folder with boost 1.44.0 and I need both msvc and
When you are debugging a program and you hover over a GUID variable, MSVC
I know MSVC can do this via a pragma message -> http://support.microsoft.com/kb/155196 Does gcc
With msvc, is there an equivalent to gcc's __builtin_return_address? I'm looking to find the
I use the MSVC with STL on VS. The autocomplete suggestions that it gives
I want to use MSVC compiler to build a DLL file. The problem is
I have an MSVC project that uses freetype, and now I'm trying to move

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.