Re: IDL 8.0 bug -- line number of errors not given [message #72886 is a reply to message #72885] |
Tue, 12 October 2010 21:55   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Oct 12, 11:42 pm, wlandsman <wlands...@gmail.com> wrote:
> But if I use CATCH I need to add a whole paragraph somewhere (where?)
> in the code
>
> Catch, theError
> IF theError NE 0 THEN BEGIN
> Catch, /Cancel
> void = Error_Message()
> RETURN
> END
>
> So what are the advantages of using CATCH? (This is not a trick
> question -- I've had a mental block about how to use CATCH.) --Wayne
To just throw an error message and return, not many advantages indeed:
One is having only one place to send a common error message, instead
of several tests, all with the same argument to message. Another is
not stopping execution, like David mentioned.
But I find that the main use of catch is to handle the errors, not
just send error messages. It can be part of the approach of 'asking
for forgiveness' (handling the errors) instead of 'asking for
permission' (testing to avoid errors). Sometimes it is much easier to
rely on an error occurring (and handling it) than to test for many
potentially complicated possibilities.
|
|
|