Defining an Exception Class
It is extremely easy to build an exception class, from a technical point of view. In the Class Builder, you decide on an exception class and then choose from which of the three named superclasses your class is to inherit.
Under the Texts tab, you can create translatable texts in the online text repository and they are filled at runtime. Using a special method that each exception class inherits, you can access these texts. You can also create several texts for the same class and, when an exception is thrown, define which text is to be used. You can also use alternative texts in message classes for exceptions.
If you need other values, you can create as many class attributes as you wish. Always take the technical information on the exception your program needs from the attributes. Do not attempt in ay way to analyze the text off the class for this purpose.
If you wish to throw an exception yourself, choose a semantic approach. This means: Go in to the syntactical details as late as possible. Do precise conceptual work first.
· Analyze the situation.
· Describe the situation in as abstract a way as possible, and with as much detail as required.
· Check whether there is already an exception class that is suitable for your purposes.
· Define a suitable exception class if you do not have one already.
Analyzing means primarily thinking whether an exception is a good idea or whether an assertion or a return code would be more suitable.
Then formulate precisely the decisive features of the exception situation and extract from the position where the exception occurs because that would prevent reusability of the exception class.
As soon as you have listed the decisive characteristics, check whether there is already an exception class with these features. If a class almost fits, you can add an additional text or inherit from it and definition additional attributes, should you require them.
However, never inherit from a superclass that represents a different error type from the one that your require. In some cases, it can also be a good strategy to define a more abstract exception class and then to inherit your class from this class.