Zen API
|
Most Zen functions return a kStatus value to the caller, which can be used by the caller to detect errors. Common kStatus values include kOK (no error), kERROR (general error), and kERROR_PARAMETER (invalid parameter).
A variety of error-handling macros are provided to simplify the process of dealing with error codes. The most common error-handling macro is kCheck:
Other error-handling macros are provided to simulate the structure of exception handling. For example, kTry/kCatch:
Or kTry/kFinally, which can be used to perform clean-up regardless of whether an error has been detected:
kTry/kCatch and kTry/kFinally are the most common forms of exception-handling in Zen. However, an extended form is provided that allows kCatch and kFinally behaviours to be combined:
In the extended form, an "Ex" suffix is used to distinguish kCatchEx from kCatch, kFinallyEx from kFinally, etc.
In all of the exception-handling methods, the kTry and kTest macros have the same behavior. kTry is always used to start an exception-handling block, and kTest is always used to check status values within a kTry block. The use of kTest within a kTry block is analogous to the use of kCheck anywhere else.
Because the Zen exception-handling macros are implemented with labels and local jumps (goto), it is efficient to generate exceptions and efficient to handle them. Accordingly, there is no need to avoid Zen exception-handling logic in performance-critical sections. However, one limitation of the Zen exception-handling macros is that only a single exception-handling block is permitted per function. This prevents the nesting of exception logic within a single function.