Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: How do I manipulate SQL errors?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Let's suppose that table is empty.
How do I manipulate this error:

ibquery1.close;
ibquery1.sql.clear;
ibquery1.sql.add('select * from TABLEMASTERX where master1='teste';');
ibquery1.open;

I want show a message telling that there are an error X and exit from procedure.

I want to do this (several bugs):

on error goto quit1;
ibquery1.close;
ibquery1.sql.clear;
ibquery1.sql.add('select * from TABLEMASTERX where master1='teste';');
ibquery1.open;
on error goto 0;
goto continue1;

quit1:
messagedlg ("Error nº: X",mtinformation,[mbok],0);
halt;

continue1:
...
 
An empty table won't really throw an exception on it's own. But you could do something like this:

in your interface section, define a custom exception:
type
EEmptyTable = class(Exception);

in your procedure, wrap your code in a try finally block and raise an exception when your error condition(s) occur. When an exception is raised the rest of the procedure is skipped and the except block is executed. It's a lot different than VB but the same basic things can be accomplished.

try
 ibquery1.close;
 ibquery1.sql.clear;
 ibquery1.sql.add('select * from TABLEMASTERX where master1='teste';');
 ibquery1.open;
if ibQuery1.eof then
raise EEmptyTable.Create('The table is empty');
//continuing code here
except
on EEmptyTable do
ShowException(ExceptObject, ExceptAddr);
end;



 
This only manipulate one error. It verifies if table is
empty, but...

How do I manipulate other errors?
 
I try to use, but don't work:
use IB; -> I add IB.PAS

ibquery1.close;
ibquery1.sql.clear;
ibquery1.sql.add(memo1.text);
try
ibquery1.open;
except
on e:eibinterbaseerror do
showmessage ('Error: '+ e.message);
end;
showmessage ('Procedure completed!');

Any help?
 
What part isn't working? Is it not catching all errors? It may be throwing a different kind of exception, EDBEngineError or other, that you need to catch as well. You could catch all exceptions by simply putting on E:Exception do instead of a specific exception type.

TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top