Error Handling

B

Bill Sturdevant

1. Is there any way to create a centralized error handler
that will intercept all errors, or is it necessary to have
error handling logic in every routine?

2. If I have a routine "A" with error handling and
routine "A" calls sub routines "A1", "A2", "A3" and "A4",
will the error handler in routine "A" catch all the errors
in itself plus all the errors in "A1", "A2", "A3" & "A4"?
 
M

Marshall Barton

Bill said:
1. Is there any way to create a centralized error handler
that will intercept all errors, or is it necessary to have
error handling logic in every routine?

Just about, Yes.

2. If I have a routine "A" with error handling and
routine "A" calls sub routines "A1", "A2", "A3" and "A4",
will the error handler in routine "A" catch all the errors
in itself plus all the errors in "A1", "A2", "A3" & "A4"?


Well, yes it will. Errors "bubble up" to a higher level
procedure that does have an error handler. You can even use
the Raise method to force this. But, the big problem in
doing this is that the one error handler may not be able to
figure out what went wrong, while the lower level procedure
already "knows" what was happening when the error occured.
 
M

Marshall Barton

Steve said:
I think Marsh is responding to the second part of your question ;-)


That certainly was an ambiguous answer :-\ Sorry about
that Bill, too busy getting ready for the family Christmas
Eve get together.

To clarify, No, you can't create a centrailized error
trapping procedure. You should have at least the error
trapping in each and every procedure. Of course you can
place the code for any common logic (e.g. logging errors to
a file) in a public procedure.
 
J

Jonathan Parminter

Hi, just a thought that a way to manage error handling is:

1. To ensure that each procedure only has one purpose. It
means that you end up with many procedures. But a benefit
is that the error handler for each procedure can 'focus'
on the errors for that procedure and so they (the error
handlers) are likey to be less complex. Although some
programmers like to use inline error handling for the same
reason.

2. Avoid duplicating code (and their error handlers) by
creating common/shared procedures. Call these common
procedures instead of repeating yourself...

Well, I guess you knew this...

Happy new year
Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top