rocedure tform1.myexception(Sender: TObject; E: Exception)
if e.message = 'xx' then
begin
//ADOConn.Connected := false;//if use ado
//Database1.Connected:=false;//if bde was used
//or close one by one
//or for i:=0 to componentscount-1 do
// if components is tadoquery then
// (components as tadoquery).close;
end;
end;
procedure form1oncreate...
begin
application.onexception := myexception;
end;