Re: Returning an error message when something goes wrong

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Steve McLellan (sjm)
Date: 12/07/04


Date: Tue, 7 Dec 2004 10:50:21 -0000


"Simon" <sh856531@microsofts_free_email_service.com> wrote in message
news:%23RC$8vT2EHA.2180@TK2MSFTNGP10.phx.gbl...
> Hi everyone,
>
> I'm wondering what you're supposed to do when you call a method that is
> required to perform some action but that action subsequently fails. More
> specifically, how do you get a custom message back so that you can provide
> some useful information to the application user?
>
> It seems we dont have much room for manouever.
>
> Example:
>
>
> I might have a method called load file which is supposed to return a file
> object. Inside this method a problem is detected and the file object can't
> be loaded correctly.
>
> The only way i can see to return context based error messages is to throw
> an exception. However, I don't see how you can reconcile the use of
> exceptions in non-exceptional circumstances given the general wisdom that
> says you should only throw exceptions when something truly unexpected has
> happened.
>
> Thanks in advance for any advice you can offer.

This IS exceptional - a file you tried to load could not be loaded. This is
what exceptions are for - passing empty parameters by reference and filling
them is not a good way to go about things. You can always catch exceptions
from a calling method, which lets you do whatever needs to be done and
display appropriate messages etc.

Steve