From: Tony Johansson on
Hi!

Some exception has further information in the Inner Exception property.
For example the SmtpException has useful information in the InnerException
that can be used
Here is an example
catch (SmtpException ex)
{
Exception inner = ex.InnerException;
MessageBox.Show("Could not send message: " + inner.Message,
"Problem sending message", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

So my question is why is not the InnerException.Message information put into
the SmtpException.Message ?

//Tony


From: Willem van Rumpt on
Tony Johansson wrote:
> Hi!
>
> Some exception has further information in the Inner Exception property.
> For example the SmtpException has useful information in the InnerException
> that can be used
> Here is an example
> catch (SmtpException ex)
> {
> Exception inner = ex.InnerException;
> MessageBox.Show("Could not send message: " + inner.Message,
> "Problem sending message", MessageBoxButtons.OK,
> MessageBoxIcon.Error);
> }
>
> So my question is why is not the InnerException.Message information put into
> the SmtpException.Message ?
>
> //Tony
>
>

What use would it be to copy and repeat the same message in a new
exception? The wrapping exception can (potentially) be more clear and
provide additional information than the exception thrown from some deep
ly nested library call.

--
Willem van Rumpt
From: Harlan Messinger on
Tony Johansson wrote:
> Hi!
>
> Some exception has further information in the Inner Exception property.
> For example the SmtpException has useful information in the InnerException
> that can be used
> Here is an example
> catch (SmtpException ex)
> {
> Exception inner = ex.InnerException;
> MessageBox.Show("Could not send message: " + inner.Message,
> "Problem sending message", MessageBoxButtons.OK,
> MessageBoxIcon.Error);
> }
>
> So my question is why is not the InnerException.Message information put into
> the SmtpException.Message ?

An Exception isn't just a message. It has a type, and it has a a
HelpLink, a Source, a StackTrace, and a TargetSite. It may even have its
own InnerException. All of these may be useful to a calling method or to
the user or developer.
From: Göran Andersson on
On 2010-05-04 12:26, Tony Johansson wrote:
> Hi!
>
> Some exception has further information in the Inner Exception property.
> For example the SmtpException has useful information in the InnerException
> that can be used
> Here is an example
> catch (SmtpException ex)
> {
> Exception inner = ex.InnerException;
> MessageBox.Show("Could not send message: " + inner.Message,
> "Problem sending message", MessageBoxButtons.OK,
> MessageBoxIcon.Error);
> }
>
> So my question is why is not the InnerException.Message information put into
> the SmtpException.Message ?
>
> //Tony
>

An exception is usually put as inner exception if it contains
information that needs to be retained and can't be combined into a new
exception. An exception can contain a lot more than just the message,
like a stack trace.

A clear example is the SoapException which is thrown when a web service
call is answered with a SOAP error message. If the web service is a .NET
service, the error message contains a serialised excpetion object from
the server. This is deserialised and put in the InnerException of the
SoapException object. As the exceptions are created on different
servers, they should clearly remain separate instead of trying to be
combine them.

--
G�ran Andersson
_____
http://www.guffa.com
From: Patrice on
> So my question is why is not the InnerException.Message information put
> into the SmtpException.Message ?

Common best practice. It's best to provide separated information that can be
gathered easily as needed rather than to pack all in a single item making
hard to extract a particular info out of it.

Not sure what you want to get in your case, but you could perhaps try
ex.ToString()...

--
Patrice



 |  Next  |  Last
Pages: 1 2
Prev: validate wmf files?
Next: Local service account