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 8159713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:00:54+00:00 2026-06-06T18:00:54+00:00

I need my methods to throw custom exceptions but it keeps giving me this

  • 0

I need my methods to throw custom exceptions
but it keeps giving me this error :
error C2059: syntax error : 'string'

I was reading the following link but it doesn’t solve my problem:
http://msdn.microsoft.com/en-us/library/t8xe60cf%28VS.80%29.aspx

This is the code I have:

#include <exception>
#include <stdexcept>
#include <string>
#include "Log.h"

LOG_USE()

class Exception : public std::exception 
{
    public:
        explicit Exception(std::string msg)
            : message(msg)
        {}
        ~Exception()
        {}

        virtual const char* what() const  throw() 
        {
            LOG_MSG(message) // write to log file
            return message.c_str();
        }

    private:
        std::string message;
};

#endif

Somewhere in my app I have methods that look like this:

.....
....
void view::setDisplayView(ViewMode mode) throw(Exception("setDisplayView error"))
{
    ;
}
....
....

What am I doing wrong here?
I’m using Visual Studio 2008 on 32-bit Windows XP.

  • 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-06-06T18:00:55+00:00Added an answer on June 6, 2026 at 6:00 pm

    You’re not using exception specification correctly. That throw, which follows the declaration of setDisplayView, should only contain a type (in your case, Exception), not an object (which is what you get with that Exception("setDisplayView error")).

    Now, having that said, exception specifications are deprecated in C++11, and have not been considered a useful feature before. Better just omit that throw(Exception("setDisplayView error")). Use exception specifications only if you’re not going to throw anything. In that case, the new syntax to use would be nothrow.

    Edit:

    To signify the exception has been thrown from setDisplayView, you must pass that information to the exception when it’s created –

    void view::setDisplayView(ViewMode mode)
    {
         if (badThingHappened())
              throw Exception("setDisplayView error");
    }
    

    There are various non-standard techniques to find the origin of the exception when catching it, you can find some here. Using exception specification is just not one of them…

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

Sidebar

Related Questions

I need to globally redirect my users if a custom error is thrown in
I need two methods one to encrypt and one to decrypt an xml file
I am currently integrating lua with C++. For lua I need static methods which
I need to call methods from ANALYS32.XLL Excel add-ins for analysis toolpak into mu
In a UITableViewController subclass, there are some methods that need to be implemented in
I am trying to write integration tests. Therefore I need the start methods of
I need to call some methods in Wininet.dll from a Java program. I can
I need to run some methods before the first call of a wcf service,
I need CEDET for eassist ( eassist-list-methods is quite handy). In eassist.el there's the
I need to implement time calculation for repository methods in my asp .net mvc

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.