Jump to content
NamoRamana

FireDAC Exception handling without driver info

Recommended Posts

When I catch any DB exception arising upon an execution of a query/sp, the "e.message" contains driver info text in the starting the message.. Example: e.message comes as:

 

"[FireDAC][Phys][ODBC][Microsoft]

[SQL Server]Divide by zero error encountered."


 

Is there any way to suppress the driver info from the actual exception text?

 

Share this post


Link to post

Have you tried using regex?

 

uses
    ...
    System.RegularExpressions;
    
    
    ...
    
    try
      ...
      // some database function
    
    except
      on E: EFDDBEngineException do
      begin
        ShowMessage(TRegEx.Replace(E.Message, '\[[^\]]*\]', ''));
      end;
      on E: Exception do
      begin
        ShowMessage('An unexpected error occurred: ' + E.Message);
      end;
    end;

 

Share this post


Link to post

That message comes from the underlying database so knowing which database is helpful in interpreting it. Seems counterproductive to be removing context from error messages.

Share this post


Link to post

It also tells which layer produced the error. For example, was it the DB server, the DB client library, or FireDAC itself.

It's technical info that provides important context to the developer/supporter. It's not meant to be presented to the user.

Share this post


Link to post
On 11/26/2024 at 2:02 PM, NamoRamana said:

 

Is there any way to suppress the driver info from the actual exception text?

 

There isn't a property or global setting that will do that.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×