Exception handling
Posted: Tue Sep 10, 2019 9:53 am
Hello,
I'm now trying to find a correct error handling procedure with central exception handlers, but I'm not sure if this is a good practice.
Please see the following code:
This code works as expected, but I have my doubts if this is the optimal solution.
As background: I'm writing a production planning software that can be used with a GUI and only from command line (as planned task), and delegating the error handling from the library to the calling executable helps me cover all needs.
Wolfgang
P.S. this is inspired by the VO Errorblock and the discussion about error handling in migrated VO applications
I'm now trying to find a correct error handling procedure with central exception handlers, but I'm not sure if this is a good practice.
Please see the following code:
Code: Select all
function Start( ) as void
local oProcessing as Processing
oProcessing := Processing{}
oProcessing:ExceptionHandler := HandleException
oProcessing:Process()
return
function HandleException( oEx as Exception ) as logic
System.Console.WriteLine( "Exception occurred:" + oEx:Message )
return true
delegate ExceptionHandler( oEx as Exception ) as logic
class Processing
constructor()
return
public property ExceptionHandler as ExceptionHandler auto
method Process() as void
local u as object
System.Console.WriteLine("Testing Exception Handler")
try
u := "Hi"
u := int( u ) + 123
catch oEx as Exception
if self:ExceptionHandler != null
self:ExceptionHandler:Invoke( oEx )
endif
end try
return
end class
As background: I'm writing a production planning software that can be used with a GUI and only from command line (as planned task), and delegating the error handling from the library to the calling executable helps me cover all needs.
Wolfgang
P.S. this is inspired by the VO Errorblock and the discussion about error handling in migrated VO applications