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

...handle an exception?

Previous pageReturn to chapter overviewNext page   

EurekaLog automatically catches any unhandled exceptions in your application. However, you may want to force-handle exception coming from a specific code:

 

try
  // ... some code ...
except
  on E: ENetworkError do
  begin
    // How to handle this?
  end;
end;

 

If this is the case - then you can use any of the following:

1. [VCL] Application.HandleException(nil); from Forms unit
2. [VCL] Application.ShowException(E); from Forms unit
3. [RTL] ApplicationHandleException(nil); from Classes unit
4. [RTL] ApplicationShowException(E); from Classes unit
5. [EurekaLog] HandleException(E); from EBase unit
6. [EurekaLog] ShowExpected(E); from EBase unit

 

For example:

 

try
  // ... some code ...
except
  on E: ENetworkError do
    Application.HandleException(nil);
end;

 

or:

 

try
  // ... some code ...
except
  on E: ENetworkError do
    ApplicationShowException(E);
end;

 

This code will show a usual error message box when EurekaLog is not enabled/active, but it will show full EurekaLog's dialog (with call stack, sending, etc.) when EurekaLog is enabled and active.

 

Note: use item 6 (ShowExpected) only if you want to consider current exception as "expected".

 

Important Note: If you are going to handle exception from another thread (for example, when you are analyzing .FatalException property of a background thread in the main thread) - be sure to use function which allows you to specify exception object directly. For example, Application.HandleException function will try to use current exception, it does not know about your thread and its .FatalException property. It will not work properly for your purpose. On the other hand, Application.ShowException allows you to specify an exception object as the first argument. Thus, you may pass your MyThread.FatalException to it.

 

Important Note: If your exception was not raised yet - then EurekaLog will ignore it. If you want to force EurekaLog to handle such exception - see this article.

 

 

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_handle_exception.php