dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Intermediate
Jan 28, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Rules of Thumb for Designing Exception Classes

When designing an exception class, think of it as a standalone class with data members and member functions. A well-designed exception class should have a member function that returns a verbal description of the exception. In applications that use error codes, you should also include a member function that returns the exception's numeric code. This way, the handler of that exception doesn't need to look for this information elsewhere; it can retrieve it from the exception object directly.

 
  class myException
  {
  // ..stuff
  public:
    const char * description() const;
    int code_number() const;
  };

  catch( myException & ex)
  {
    cout<<" error occurred: "<< ex.description();
    cout<< "with code: " << ex.code_number(); 
  }

Remember also that sometimes the same exception can be thrown in similar but not identical situations. For example, a DBMS system can throw the same exception when it encounters a referential integrity problem or an attempt to insert a duplicate key. To distinguish between these errors, the handler can query the exception object and obtain a precise description of the actual error that occurred.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date