On Fri, 18 Mar 2005 11:16:37 -0600, Rob Kennedy <[EMAIL PROTECTED]> wrote:
> Richard ONeil wrote:
> > You could try something like:
> >
> > try
> > database.open();
> > except
> > on e: exception do
> > if e is edbengineerror then
> > begin
> > raise edatabaseerror.create('omg....something just happened!!');
> > end;
> > end;
>
> Sorry, that's a terrible example of catching exceptions, for two reasons:
>
> 1. If the code in the "try" section raises anything other than an
> EDBEngineError, it will be caught and ignored. You'll never know about
> it at run time. Never catch an exception that you don't know how to handle.
>
> except
> on E: EDBEngineError do begin
> // ...
> end;
> end;
>
> 2. It hides the original exception by raising a new, less specific
> exception with a meaningless error message. It also throws away the
> database error code. I'm not sure, but it might also clobber whatever
> stack trace might have been available from a debugging library like
> JclDebug.
>
> --
> Rob
>
Hi Rob
Why is this a terrible example? If you are worried about your other
exceptions, then build routines to handle them and a generic for ones
that you don't know about. The message that is being raised was just
an example that you can inform your user that something has happened.
There is nothing to stop you from logging the actual error that
happened. Why would you scare your user to death by showing them the
actual exception? Be gentle with them.
By creating different handlers for the known types of errors allows
you to tailor the message that is given back, and handle it
gracefully.
You are correct that the above example would probably be bad by
itself, but from an educational standpoint, I was hoping that it would
be a good starting point. :)
I could be wrong, though....this is just how I was taught.....not to
say it's right. :)
I've never used JclDebug....you have me curious about it, though.
Where might I find more information about it?
Thanks for the feedback, as well.
Richard
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/