Root > How to... > ...handle an exception? > ...emulate an exception?

...emulate an exception?

Previous pageReturn to chapter overviewNext page   

If you want to "handle" an exception which was not raised yet, e.g.:

 

E := Exception.Create('Message');
Application.ShowException(E);
FreeAndNil(E);

 

Then you have to specify some additional details, for example:

 

uses
  {$IFDEF EUREKALOG} 
  ECallStack,        // for GetCurrentCallStack and TEurekaBaseStackList
  EClasses,          // for TEurekaModuleOptions
  EExceptionManager, // for ExceptionManager
  ETypes,            // for mtErrorMsgCaption
  {$ENDIF EUREKALOG}
  //  ...
 
//  ...
 
var
  E: Exception;
  {$IFDEF EUREKALOG}
  EI: TEurekaExceptionInfo;

  Stack: TEurekaBaseStackList;
  {$ENDIF EUREKALOG}
begin
  E := Exception.Create('Message');
 
  {$IFDEF EUREKALOG}
  EI := ExceptionManager.Info(Pointer(E), nil);
  if Assigned(EI) then
  begin

    // Required, emulates "raising" of the exception

    Stack := GetCurrentCallStack;

    try 
      EI.CallStack := Stack;

    finally

      FreeAndNil(Stack); 

    end
    
    // Optional, just an example
    EI.Options.CustomizedTexts[mtErrorMsgCaption] := 'Notification';
  end;
  {$ENDIF EUREKALOG}
 
  Application.ShowException(E);
  FreeAndNil(E);
end;

 

Some information related to exception's raising will be missed (such as exception's address, CPU, and assembly info), so you may want to disable these in options.

 

If you don't mind debugger's notifications - then you may use shorter alternative:

 

try
  raise Exception.Create('Message');
except
  ApplicationHandleException(nil);
end;

 

And if you don't care about exception object either - you may use:

 

uses 
  EExceptionManager; // for ExceptionManager
 
// ...
 
ExceptionManager.StandardEurekaError('Message');

 

Of course, you may also alter options:

 

uses 
  EClasses, // for TEurekaModuleOptions
  EModules, // for CurrentEurekaLogOptions
  EExceptionManager, // for ExceptionManager
  ETypes; // for mtErrorMsgCaption
 
// ...
var

  Options: TEurekaModuleOptions;

begin
  Options := TEurekaModuleOptions.Create('');
  try
    Options.Assign(CurrentEurekaLogOptions);
 
    // This is just an example. Alter options as you like
    Options.CustomizedTexts[mtErrorMsgCaption] := 'Notification';
 
    ExceptionManager.StandardEurekaError('Message', Options);
  finally
    FreeAndNil(Options);
  end;

end;

 

 

See also:




Send feedback... Build date: 2018-11-26
Last edited: 2018-11-13
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_emulate_exception.php