Rules of Thumb for Designing Exception Classes

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&lt&lt "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.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several