General Exception Guidelines
- Follow the processing specification for the method, this should describe the error situations that can be encountered. When actually writing and testing the code, look out for sources of errors that might have been overlooked.
- Do not try to add a "catch-all" for unanticipated errors; the server infrastructure can handle these better than you can. Do not wrap entire operations with error handlers.
- Do handle exceptions where you are in a position to add more specific information about what has happened, such as converting "record not found" into "bank account not found".
- Do gain an understanding of the standard exceptions defined in the core infrastructure. Be aware of the types of exceptions that can be thrown by generated database manipulation operations of entity objects:
- RecordNotFoundException can be thrown by singleton reads, updates and removes of the database (entity read, nsread, modify, nsmodify, remove and nsremove operations). A non standard operation (for example nsmodify and nsremove) will throw this exception irrespective of the uniqueness of the key that is passed into it.
- RecordNotFoundException can be thrown by nonkeyed updates and removes of the database (entity nkremove and nkmodify).
- RecordDeletedException is always thrown in precedence to a RecordNotFoundException.
- RecordDeletedException can be thrown when an optimistic update fails because the target record has been deleted . With optimistic locking enabled the record is re-read to obtain the version number. If the record is no longer present this exception is thrown.
- DuplicateRecordException can be thrown by insert and update operations (entity insert, nsinsert, modify, nsmodify, nkmodify operations).
- RecordChangedException and RecordDeletedException can be thrown by update operations with optimistic locking. RecordDeletedException is thrown by entities which have optimistic locking enabled in preference to RecordLockedException.
- MultipleRecordException can be thrown by singleton reads of the database (entity read, nsread, nkread operations) if multiple records are found which meet the specified selection criteria.
- ReadmultiMaxException can be thrown by multiple reads of the database (entity readmulti, nsmulti, nkreadmulti operations) if more record are retrieved than the maximum specified in the application model.
- RecordLockedException can be thrown by any of the entity operations if a deadlock or lock timeout occurs.
- OtherDatabaseException can be thrown by any of the entity operations if the database reports an error which does not map to one of the above exceptions.