Root > Advanced topics > Using EurekaLog in DLL > Using exception tracer with frameworks in DLLs > Single instance of exception tracer

Single instance of exception tracer

Previous pageReturn to chapter overviewNext page   

Create new DLL project, enable EurekaLog and set project type to "Lightweight DLL". Since we're going to use forms in our DLL - go do Advanced/Code/Hooks page in EurekaLog project options and enable "VCL Forms application" option.
 
Now, create a new form for DLL, place a button to raise exception:

 

...
 
type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.Button1Click(Sender: TObject);
begin
  raise Exception.Create('Error Message');
end;
 
...

 

And change DLL code as:

 

library Project2;
 
uses
  // Automatically generated by EurekaLog
  EAppDLL,  // "Lightweight DLL" profile
  EAppVCL,  // "VCL Forms application" hook
 
  // Added manually
  Windows,
  SysUtils,
  Classes,
  EBase,
  Unit2 in 'Unit2.pas' {Form2};
 
{$R *.res}
 
procedure Test1;
begin
  try
    raise Exception.Create('Error Message');
  except
    on E: Exception do
      // Ask exception manager in host application to process this exception
      HandleException(E); // EBase unit
  end;
end;
 
procedure Test2;
var
  Form: TForm2;
begin
  try
    Form := TForm2.Create(nil);
    try
      Form.ShowModal;
    finally
      FreeAndNil(Form);
    end;
  except
    on E: Exception do
      // Ask exception manager in host application to process this exception
      HandleException(E); // EBase unit
  end;
end;
 
exports
  Test1, Test2;
 
end.

 

As usual - we are using EBase unit to handle exceptions.

 

The first function in our DLL will just raise exception in DLL function. Basically, it is the same as second function in our previous example.

 

Second function will create and show a modal form. There is no exception inside function itself, but form contains button to raise exception. This exception will not be catched by our try/except block, because exceptions in form's event handlers are handled by VCL framework. That's why we need EAppVCL unit (it contains hooks for VCL). Try/except block in second function will catch exceptions only for form's creating or destroying.

 

That's all. Save all and compile. Run application and hit all buttons. First button is not changed at all. Second button and third button behave differently:

 

 

Button #2: Exception did not escape DLL, it was handled by DLL by displaying complete bug report
Call stack shows mixed exe/DLL lines
 

 

Button #3: Exception was raised by form. It was handled by VCL.
EurekaLog hook displays full bug report
Call stack shows mixed exe/DLL lines




Send feedback... Build date: 2024-12-19
Last edited: 2023-03-07
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/dll_single_instance_2.php