Description |
Microsoft has introduced a wonderful means of tracking the path of an exception through an application. Each level of nesting of exception handling can be captured. There is a base exception that is the lowest level, base exception that started the eexception chain. This GetBaseException method returns this exception object.
|
|
Microsoft MSDN Links |
System
System.Exception
|
|
|
A simple example |
program Project1;
{$APPTYPE CONSOLE}
type
NestedException = System.ApplicationException;
var
x : Integer;
zero : Integer;
begin
zero := 0;
try
try
x := 1 DIV zero;
Console.WriteLine('Division succeeded x = {0}', x.ToString);
except
On E : exception do
Raise NestedException.Create('Inner exception invoked', E);
end;
except
On E : Exception do
begin
Console.WriteLine('This Exception :');
Console.WriteLine;
Console.WriteLine(E.ToString);
Console.WriteLine;
Console.WriteLine('Base Exception :');
Console.WriteLine;
Console.WriteLine(E.GetBaseException.ToString);
end;
end;
Console.ReadLine;
end.
| Show full unit code | This Exception :
System.ApplicationException: Inner exception invoked ---> System.DivideByZeroException: Attempted to divide by zero.
at Project1.Unit.Project1() in C:\Documents and Settings\Neil\My Documents\Borland Studio Projects\Project1.dpr:line 16
--- End of inner exception stack trace ---
at Project1.Unit.Project1() in C:\Documents and Settings\Neil\My Documents\Borland Studio Projects\Project1.dpr:line 20
Base Exception :
System.DivideByZeroException: Attempted to divide by zero.
at Project1.Unit.Project1() in C:\Documents and Settings\Neil\My Documents\Borland Studio Projects\Project1.dpr:line 16
|
|
|
|