Unit 3 - Lesson 4 - Exception Handling Flashcards
List two forms of exceptions
AppException - checked exception - must catch or throw an exception. Subclass of curam.util.exception.AppException) AppRuntimeException - unchecked exception - e.g. RecordNotFound - doesn't have to catch or throw. Inherit from Java's Exception and RuntimeException classes.
Where exceptions can originate from
Generated code:
Database Access Layer (typically unchecked exceptions)
Remote Interface Layer (RIL)
Handcoded code:
Business Object Layer (can be pre-defined or customised exceptions)
All Facade and Process object methods throw AppException and InformationalException.
Advantages of exceptions
Recommended mechanism for handling errors.
Single exception try/catch can enclose many statements, each of which could raise an exception.
describe Handling exceptions
- Ignored, in which case it filters up to the RIL
- Caught and ignored
- Caught, information added, and re-thrown
- Caught, a new exception created, and thrown
describe general RIL exception handling
- Get message text from catalog (messages.jar, must rebuild the client whenever the message catalog has been changed)
- If exception not handled, get default message.
- Log the exception if setLoggable = true
- Create an exception and throw to the client
- Client looks up localised text and displays
Describe message catalogs
Message file is an XML file stored in the components\core\message directory
Usually one per BPO
How to generate message catalog
build msggen generates BpoValidateAccount.xml into:
BpoValidateAccount.properties file contains the message text file (1 per locale)
BPOVALidaTEACCOUNT.java containing the message catalog identifiers.
Part of the build generated.
Must build client whenever the message file changes.
Explain tags in message.xml file
Messages -> Message -> Locale
Messages - entire content root
Message where name is Java identifier for this message.
Locale - element has message description - after generation this text is copied to the properties file for the message.
Simple exception in Java
throw new AppException (serverworkshop.message.BPOVALIDATEACCOUNT.ERR_ACCOUNT_ALREADY_EXISTS)
Describe Message Arguments
Argument place holders are tokens included in the error message source text and replaced by an argument at runtime.
Form of %nc where n is argument number and c is a single character denoting the argument type.
Can be attached to an exception before it is thrown.
intended to be included in the error message displayed to the client e.arg(arg0.setupDate)
List message argument types
s - string n - numeric d - date t - time z - date/time c - code table item
Logging exceptions
To log to the application log file by RIL:
* Use the exception’s setLoggable method.
* e.setLoggable(true)
Luggable if its luggable flag is set, or if the luggable flag is set on any attached exceptions.
Any other exceptions attached are also logged.
Loggable exceptions are written to the application log file by the RIL.
Logging facilities are provided by curam.util.resources.Trace, wrapper for Log4j API.
Where is defined application log file
The application log file is defined here: application.prx (curam.trace.configfile.location)
RecordNotFoundException
Singleton reads, updates and removes. read, nsread, modify, nsmodify, remove, nsremove, nkremove, nkmodify
RecordDeletedException
When optimistic locking fails because the target record has been deleted.