Download GemStone/S Programming Guide
Transcript
Handling Errors Handling Errors in Your Application Categories and Error Numbers Errors are defined in an instance of LanguageDictionary. Each LanguageDictionary represents a specific category of errors. Your application can include any number of such error dictionaries, each representing a given category of error. However, each such category of errors must be defined in UserGlobals or some other dictionary to which your application has access. Like the SignalDict SymbolDictionary described earlier, the dictionary that defines your errors is keyed on symbols such as #English or #Kwakiutl that name natural languages. Each key is associated with an array of error-describing objects. The index into the array is a specific error number, and the value is either a string or another array. If it is a string, the string represents the text of an error message. Using an array, however, allows you to capture and report diagnostic information from the context of the error. This works just as it did using the signaling mechanism described earlier; SmallIntegers interspersed with strings act as indexes into an array of arguments passed back from the specific error that was raised. When the error string is constructed, each positive SmallInteger in the error object is replaced by the result of sending asString to the corresponding element of the args: array specified when the exception is raised. (This array is discussed in detail in the next section.) The GemStone system itself uses this mechanism. GemStone errors are defined in the dictionary GemStoneError, and all GemStone system errors belong to this category. This dictionary is accessible to all users by virtue of being defined in the dictionary Globals. The dictionary GemStoneError contains one key: #English. The value of this key is an array. It is not, however, an array of error numbers. Numbers are not the most useful possible way to refer to errors; sprinkling code with numbers does not lead to an application that can be easily understood and maintained. For this reason, GemStoneError defines mnemonic symbols for each error number in a SymbolDictionary called ErrorSymbols. The keys in this dictionary are the mnemonic symbols, and their values are the error numbers. These numbers, in turn, are used to map each error to the appropriate index of the array that holds the error text. This structure is diagrammed in Figure 11.2. December 2001 GemStone Systems, Inc. 11-9