Page 1 of 1
					
				How to manage exceptions ?
				Posted: Fri  25 Jun 2010 15:53
				by yapt
				Hello,
I am trying to manage specific exceptions on PgDAC.
In example, I am trying to do a post on a table but a field must not be null (a primary key for example):
Code: Select all
try
  myPgTable.Post;
except
  on E: EPgError do
  begin
     ShowMessage('it is a PgDAC Exception');
  end;
  on E: EDAError do
  begin
     ShowMessage('it is a .... Database Exception on the server side ?');
  end;
  on E: Exception do
  begin
     ShowMessage('it is a generic exception');
  end;
end;
But the exception is a generic EDatabaseError exception.  With a very limited information inside.
How I must to "manage" PgDAC exception ?  I have been looking for something in the documentation but I cannot find anything usefull.
Thanks.
 
			
					
				
				Posted: Tue  29 Jun 2010 11:14
				by bork
				Hello
To handle PgDAC exceptions you can use the following code:
Code: Select all
    on E: EPgError do
    begin
       ShowMessage('It is a PgDAC Exception: ' + E.ErrorCode + ' - ' + E.Message);
    end;
To implement this code you should add the PgError unit to the USES section of your unit.
More detailed information about EPgError you can find in the Reference -> PgError section of the UniDAC help.
 
			
					
				
				Posted: Tue  29 Jun 2010 13:08
				by yapt
				Hello Bork,
if you see my example code on my first post, the message showed is:
So it is NOT a EPgError.  As I said, it is a 'EDatabaseError'.  Perhaps I am doing something wrong but it is very simple.
Regards.
 
			
					
				
				Posted: Wed  30 Jun 2010 10:37
				by yapt
				Any advice on this ?
Thanks...
			 
			
					
				
				Posted: Wed  30 Jun 2010 14:02
				by bork
				Hello
EDatabaseError has the Message property. EDAError has the ErrorCode property and the Message property. You can manage your exceptions by the following code:
Code: Select all
  try
    ...;
  except
    on E: EPgError do
       ShowMessage('It is EPgError: ' + E.ErrorCode + ' - ' + E.Message);
    on E: EDAError do
       ShowMessage('It is EDAError: ' + IntToStr(E.ErrorCode) + ' - ' + E.Message);
    on E: EDatabaseError do
       ShowMessage('It is EDatabaseError: ' + E.Message);
    on E: Exception do
       ShowMessage(E.Message);
  end;
If you want to manage your exceptions with other results please give a detailed description of it and I will try to help you.
 
			
					
				
				Posted: Wed  30 Jun 2010 15:18
				by yapt
				Hello Bork,
perhaps I have not explain myselft right.  My problem is a PgTable.Post go inside EDatabaseError exception manager but NOT EpgError nor EDAError and I would like to get the "extended" information on a EPgError exception manager.
On your example:
Code: Select all
  try 
   [b] MyPGTable.Post;[/b]
  except 
    on E: EPgError do 
       ShowMessage('It is EPgError: ' + E.ErrorCode + ' - ' + E.Message); 
    on E: EDAError do 
       ShowMessage('It is EDAError: ' + IntToStr(E.ErrorCode) + ' - ' + E.Message); 
    on E: EDatabaseError do 
       ShowMessage('It is EDatabaseError: ' + E.Message); 
    on E: Exception do 
       ShowMessage(E.Message); 
  end;
I see this message (ShowMessage) when I execute the application and try to post to myPgTable with a field with NULL value (the field is a NOT NULL field):
'It is EDatabaseError: Field 'xxxxxxx' must have a value'
Why I cannot manage the error with EPGError ?
I hope to explain my self a bit better.
Kind regards.
 
			
					
				
				Posted: Thu  01 Jul 2010 10:10
				by bork
				Hello
The exception class depends on the place where error was generated. If error was generated by database then you will get EPgError, but if error was generated by the PgDAC components then you will get EDAError or EDatabaseError.
In your case TPgQuery or TPgTable has the Options.RequiredFields options that determine where error for required fields will be generated. If you set the value of this option to False then you will get EPgError. For standard update you cannot find difference in the behavior. But if you try to update database in the cached update mode then if this option is set to True then error for required fields will be generated on calling the Post method, but if this option is set to False then PgDAC will not check required fields and this error will be generated on storing data to database (on calling the ApplyUpdates method).
			 
			
					
				
				Posted: Thu  01 Jul 2010 13:24
				by yapt
				Hi Bork, I appreciate your explanation but ....
The exception class depends on the place where error was generated. If error was generated by database then you will get EPgError, but if error was generated by the PgDAC components then you will get EDAError or EDatabaseError. 
How can I know WHERE every exception is generated without testing everyone ?
In your case TPgQuery or TPgTable has the Options.RequiredFields.... 
My help for PgDataSet.options:
ms-help://embarcadero.rs2010/Devart.PgDac/PgDac/Devart.PgDac.TCustomPgDataSet.Options.htm
Has _only_ 9 options in spite of my IDE has 31 property options available.  I have an old help file installed I think because I have had problems with the whole Delphi help file system.  Where I can get any up to date help file and install it manually ?
Thanks...
 
			
					
				
				Posted: Mon  05 Jul 2010 12:21
				by bork
				Hello
How can I know WHERE every exception is generated without testing everyone ?
You set the Options.RequiredFields property, so you determine where exception will be generated.
My help for PgDataSet.options:
ms-help://embarcadero.rs2010/Devart.PgDac/PgDac/Devart.PgDac.TCustomPgDataSet.Options.htm
Has _only_ 9 options in spite of my IDE has 31 property options available. I have an old help file installed I think because I have had problems with the whole Delphi help file system. Where I can get any up to date help file and install it manually ? 
The TPgDataSetOptions class is inherited from the TDADataSetOptions calss. You can open your help: ms-help://embarcadero.rs2010/Devart.PgDac/PgDac/Devart.Dac.TDADataSetOptions%20members.htm and see the RequiredFields option description.
 
			
					
				
				Posted: Mon  05 Jul 2010 14:53
				by yapt
				Thanks a lot Bork.
Best regards.