Try
'Do some stuff
Try
'do stuff
Catch e As IOException
system.debuglog("Error accessing file.")
End Try
Catch e as NilObjectException
'Do stuff
end try
[quote=471575:@Michel Bujardet]Is it possible to nest try-catch ?
What if I do something like that :
Try
'Do some stuff
Try
'do stuff
Catch e As IOException
system.debuglog("Error accessing file.")
End Try
Catch e as NilObjectException
'Do stuff
end try
Would it be a valid structure ?[/quote]
This way you only catch ioexception in the inner try catch. You have different options as @Kem Tekinay suggests. You can also do a catch all at the bottom of a method.
Personally I’d suggest keeping your try catch block as small and close to the origination of the error as possible
And only catch the most restrictive of exceptions (ie/ do NOT catch RuntimeException !)
Catch what you can actually handle and no more
I’ve seen some 1000+ line methods with one giant CATCH at the bottom and trying to report anything useful from that error handler is a mess