Page 1 of 1

How to catch all exceptions?

Posted: Wed 01 Jan 2014 20:23
by stlcours
Query1 := TUniQuery.Create(Owner);
Query1.Connection:=DM.Connection;
MainForm.ds1.DataSet:=Query1;
try
with Query1 do
begin
SpecificOptions.Values['MySQL.FetchAll'] := 'True';
SQL.Clear;
SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=sssss'); // u_name is string
Execute;
end
except
on E:Exception do begin
// raise EDatabaseError.Create(E.Message);
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
end;
end;

// unidac 5.1.4
--------------------------------------------------------------
But the result is not stable, there are three different windows like these cases if I always execute the same SQL above. Why?
Image
Image
Image
Attention, the last picture is so strange. It cover the whole sreen, including the statusbar of windows(not statusbar of my application).
I hope the error window always like the first one.

Help me, thanks.

Re: How to catch all exceptions?

Posted: Thu 02 Jan 2014 10:51
by AlexP
Hello,

Please send us the error messages as text, because the links to pictures cannot be opened.

Re: How to catch all exceptions?

Posted: Fri 03 Jan 2014 11:06
by stlcours
I have send you mail. Please look at it when you are free. thanks..

Re: How to catch all exceptions?

Posted: Fri 03 Jan 2014 12:04
by AlexP
Hello,

If you use a string in a where condition, you need to put it in the quotation marks.

Code: Select all

SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=''sssss''');
If this is a string variable, use the code like the following:

Code: Select all

sssss := 'sssss';
SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=''' + sssss + '''');
If this is a parameter, use the following:

Code: Select all

SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=:sssss');
ParamByName('sssss').asString := 'sssss';

Re: How to catch all exceptions?

Posted: Fri 03 Jan 2014 15:50
by stlcours
Thanks Alex, I know well how to add the quote to the sql code of delphi. But my question is how to catch all the errors? The error above is designed by me to learn how can I catch all the errors correctly.
If possible, Even I want to get the index/number of this error of database(mysql).

Re: How to catch all exceptions?

Posted: Sat 11 Jan 2014 11:23
by AlexP
Hello,

You can use the UniConnection.onError event to process all the exceptions that occur when working with databases. When any error occurs, this event is triggered. You can analyze ErrorCode, Message, and other properties of the EDAError class and the SQL property for examining the SQL that caused the error.