inline
Jon Skeet said:
The typical thing to do is create your own exception type which
contains the invoice number, and create an exception which contains the
original exception as its "inner exception", then throw that.
Small point. That depends if he is catching some other type in a catch
handler, wrapping it in a new exception (his own custom exception object),
and then thowing the new type from the catch handler, or simply creating a
new exception of this own type anywhere in the code and throwing it.
This is the "catch-wrap-throw" technique, which can only be done from a
catch handler, versus the "throw new type" technique, which can be done
anywhere.
Another small point. His example implies that he is retrieving the exception
from a server. If this is the case then defining a custom type requires that
the assembly that contains the exception type definition be distributed so
that both client and server have access to the same assembly. Otherwise when
the exception is deserialzed on the client it will throw an exception (I
forget which one) which will mask the "real" exception.
His code shows he was accessing the innerexception property to ascertain the
cause. This is almost always a bad idea - he should access the outer
exception for the error reason and examine the inner exception(s) more for
documentation purposes then for programmatic action.