Try catch block I usually use in InterSystems ObjectScript
Hi!
Want to share with you code snippet of try catch block I usually use in methods which should return %Status.
{
try {
$$$TOE(sc,StatusMethod())
}
catch e {
set sc=e.AsStatus()
do e.Log()
}
Quit sc
}
Here $$$TOE is a short form of $$$TROWONERROR macro.
Inside macro StatusMethod is any method you call which will return %Status value. This value will be placed into sc variable.
In case of sc contains error execution will be routed to try catch block. You can wrap any Status methods calls in your code if you need to catch the errors coming from them.
In try catch block I place my logic and have to mandatory calls:
s sc=e.AsStatus() to get the status of error.
D e.Log() - to place all the stack of error to standard Application Error log which you can find in Management portal on this page:
http://localhost:57772/csp/sys/op/UtilSysAppErrorNamespaces.csp?$NAMESPACE=SAMPLES&Recent=1
How do you handle errors in your COS logic?