Evgeny,
Is it a question: try/catch (or another way of error handling) or %Status? If we try to follow some solid design principles, each method should perform only one function, have only one way to exit from, and should inform the caller whether it succeded. So, we should use both. Extending your sample:
ClassMethod solid1(parameter, ...) as %Status
{
set sc=$$$OK
try {
$$$TOE(sc,##class(x.y).a())
$$$TOE(sc,##class(x.y).b())
...
$$$TOE(sc,obj.NormalMethod(parameter))
...
} catch e {
// error handling
set sc=e.AsStatus()
}
// finally... common finalization for both (good or bad) cases
return sc
}One could write it in another fashion, e.g.
ClassMethod solid2(parameter, ...) as %Status
{
set sc=$$$OK
new $estack,$etrap
set $etrap="if $estack=0 goto errProc"
set sc=##class(x.y).a()) if 'sc goto solid2Q
set sc=##class(x.y).b()) if 'sc goto solid2Q
...
set sc=obj.NormalMethod(parameter) if 'sc goto solid2Q
...
solid2Q
// finally... common finalization for both (good or bad) cases
return sc
errProc // common error handler
// error handling
set sc=$$$ERROR(5001,"solid2 failed: "_$ze)
goto solid2Q
}Which version is better? If we don't need individual error handling of ##class(x.y).a(), ##class(x.y).b(), etc calls, I'd prefer solid1. Otherwise, solid2 seems to be more flexible: it's easy to add some extra processing of each call return. To achieve the same flexibility in solid1, we are to cover each call in an individual try-catch pair, making the coding style too heavy.
- Log in to post comments