Re: Anyone understood what InnerExceptions are?
- From: rossum <rossum48@xxxxxxxxxxxx>
- Date: Thu, 29 Mar 2007 14:05:20 +0100
On 29 Mar 2007 04:24:17 -0700, "muler" <mulugeta.abebaw@xxxxxxxxx>
wrote:
Hi all,
Why am I getting a null value to the InnerException object?
Because you haven't set it to anything, so it still has the default
value of null. You need to set it explicitly when you catch and
rethrow.
Can anyone elaborate using examples?
Yes:
static void ThrowSomething() {
throw new Exception("This is the first exception.");
}
static void CatchAndRethrow() {
try {
ThrowSomething();
}
catch (Exception ex) {
// Second parameter is the inner exception
// It preserves details of the initial error.
throw new Exception("This is the rethrown exception.", ex);
}
}
static void Main() {
try {
CatchAndRethrow();
}
catch (Exception ex) {
if (ex.InnerException != null)
Console.WriteLine("Inner Exception: " +
ex.InnerException.ToString());
else
Console.WriteLine(ex.Message);
}
Console.ReadLine();
} // end Main()
rossum
.
- References:
- Anyone understood what InnerExceptions are?
- From: muler
- Anyone understood what InnerExceptions are?
- Prev by Date: Re: Typed DataSets in VS2005
- Next by Date: Re: Typed DataSets in VS2005
- Previous by thread: Re: Anyone understood what InnerExceptions are?
- Next by thread: Calling function with pointer from a C like dll into a C# program.
- Index(es):
Relevant Pages
|