|
-
July 9th, 2012, 01:11 PM
#2
Re: Subclassing from std::exception
I prefer to subclass either std::logic_error or std::runtime_error from <stdexcept>, upon which you can simply write something like:
Code:
class MyException : public std::runtime_error
{
public:
MyException() : std::runtime_error("My error message.") {}
};
EDIT:
 Originally Posted by RobWelch
However, I've found that I can also get the functionality I want by using the std::exception ctor that takes a string to set the error message & then I don't need to override what(). This seems to me to be preferable, so I'm wondering why this isn't the standard approach to subclassing std::exception. Is there a pitfall to this approach that I'm missing?
There is no such constructor for std::exception. If there is for you, then you're using an extension to the standard library, so it is non-standard.
Last edited by laserlight; July 9th, 2012 at 01:18 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|