Home  |  Delphi .net Home  |  System.Exception  |  GetBaseException Method
  
GetBaseException  
Method  
Gets the lowest level base Exception that caused the current exception
Exception Class
System NameSpace
CF1.  Function GetBaseException : Exception;
CF : Methods with this mark are Compact Framework Compatible
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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.
   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
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author