Jump to content
alogrep

On Posterror real error ;

Recommended Posts

Hi.

 

I have this event

procedure Tdm2.APostError(DataSet: TDataSet; E: EDatabaseError;
  var Action: TDataAction);
begin
  ACTION:=DAaBORT;
end;

Then this piece of pseudocode

try  
  table.1.edit;  
  table1.post
except
  on E: SysUtils.Exception  do begin    
     if islockerror(e.errocode) then 
        repeatit()   
     else      
       dosomethingelse();;       
  end;
end;

The function islockerror() checks if the error code is one of timeut, table locked, etc.

It always returns false because the E.errorcode is always "Operation aborted".

How can I get the value of the REAL error that triggered the event?

Thanks

 

Share this post


Link to post
7 hours ago, alogrep said:

  on E: SysUtils.Exception  do begin    
     if islockerror(e.errocode) then 

 

The SysUtils.Exception class does not have an ErrorCode property.  But some descendants do, like EUpdateError, EDBClient, etc.  What is the actual ClassName() of the caught Exception?

Share this post


Link to post
18 hours ago, alogrep said:

Hi.

 

I have this event


procedure Tdm2.APostError(DataSet: TDataSet; E: EDatabaseError;
  var Action: TDataAction);
begin
  ACTION:=DAaBORT;
end;

Then this piece of pseudocode


try  
  table.1.edit;  
  table1.post
except
  on E: SysUtils.Exception  do begin    
     if islockerror(e.errocode) then 
        repeatit()   
     else      
       dosomethingelse();;       
  end;
end;

The function islockerror() checks if the error code is one of timeut, table locked, etc.

It always returns false because the E.errorcode is always "Operation aborted".

How can I get the value of the REAL error that triggered the event?

Thanks

 

In the OnPostError handler you have to store the error code (E.Errorcode) or the class of the exception passed to the handler (E.Classtype) into a field of the datamodule. Since you told the handler to abort the operation the exception you trap in the try except block will always reflect that, but you can examine the value stored by the handler to figure out what went wrong.

But be careful, it is not a good idea to execute code from an except block that may trigger another exception. Just set a flag, that indicates the action to take and act on that after the try except block.

Oh, by the way, do not store the E parameter's reference in the handler, that may become invalid after the handler returns since it probably destroys the exception object...

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

×