By defining RecoveredException and UnrecoveredException, we could determine how we would recover from an error based on these types.Further, we subclassed exceptions for two reasons:
Subclassing for these cases was effective in these cases, because:
However, with languages without type-safety, we don’t have the compiler checks. We could just as well:
Using integers or enum attributes have the benefit of being able to use switch statements for conversion of exceptions (unless it’s Python). Dictionaries are useful for generating messages for the UI. For instance, by default, Python has a string formatting feature that is written as follows: message = u"Syntax error in line {lineNumber} of the file '{filename}'".format(**exceptionAttributes) where exceptionAttributes is a dictionary of key/value pairs for the exception. This statement assigns a string to the variable message with values for {lineNumber} and {filename} taken from exceptionAttributes. A feature like this is useful in translation, since the order of the attributes may show up in a different order when the locale changes. In Japanese, it would be as follows: message = u"ファイル'{filename}'の{lineNumber}行目において、文法エラーが発生しました。".format(**exceptionAttributes) Such feature can be implemented in other languages too. Libraries based on ICU, such as AngularJS for Javascript, have this functionality and much more. |
Contents |