About %objlasterror
%objlasterror is a useful reference to the last error.
Every time $$$ERROR is called, %objlasterror is set to a result of this call.
It's important in cases where you want to convert exception to status:
Try {
// quality code
} Catch ex {
Set sc = $g(%objlasterror, $$$OK)
Set sc = $$$ADDSC(sc, ex.AsStatus())
}
Because AsStatus calls $$$ERROR under the wraps, the order is important, first you need to get %objlasterror and convert exception after that.
For Java gateway this method of handling exceptions also works:
If ((ex.Name="<ZJGTW>") && $d(%objlasterror)) {
Set sc = %objlasterror
} Else {
Set sc = ex.AsStatus()
}