Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > exception base ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9536 of 9775
Post > Topic >>

exception base class

by anon <anon@[EMAIL PROTECTED] > Apr 23, 2008 at 02:13 PM

Hello,

for debugging purposes, I am using next base class for my exception
classes:

class ErrorBase
{
  /*- Class invariants : What must be true after each call to a public
   *                     interface
   */
     public:
         explicit ErrorBase( const std::string &txt );
         ErrorBase( const ErrorBase &rhs );
         virtual ~ErrorBase();

         ErrorBase& operator=( const ErrorBase &rhs );

         virtual std::ostream& Print( std::ostream &stream ) const;

     private:

         void CreateMessage( std::ostream &stream ) const;

         virtual void PrintDetails( std::ostream & ) const;

         std::string txt;
};

then I use something like this:

class RandomError : public ErrorBase
{
   //implementation
}

const std::string errorMsg( __FILE__ + __LINE__ + "error message" );
throw RandomError( errorMsg );

I read on lots of places that the exception class should inherit from
the std::exception class and should not use std::string, because it can
throw. This article explains the problem:
http://www.boost.org/community/error_handling.html

Can anyone recommend me a better way to implement the exception
handling, which is going to give the runtime message when the error
class is thrown?

Thanks in advance.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
exception base class
anon <anon@[EMAIL PROT  2008-04-23 14:13:18 
Re: exception base class
Le Chaud Lapin <jaibud  2008-04-28 23:28:49 
Re: exception base class
Lance Diduck <lancedid  2008-04-29 10:43:22 
Re: exception base class
"Martin T." <  2008-04-29 12:09:48 
Re: exception base class
ThosRTanner <ttanner2@  2008-05-01 13:12:14 
Re: exception base class
Lance Diduck <lancedid  2008-05-03 06:12:32 
Re: exception base class
"Hendrik Schober&quo  2008-06-02 21:23:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:31:55 CDT 2008.