how to handle TQuery Error and ms sql 6.5

I have a dimamic tquery with ms sql 6.5 like:

..
query.sql.clear;
query.sql.add(MyQuery);
query.prepare;
try
  query.open;
except
  error := true;
end;
if not error then begin

  query.close
end;
query.unprepare;
...

if the sintax of  MyQuery is rong or is not a valid quary, the application
Hang's on unprepare.

AnyOne have a solution for these.
Please EMail me h...@mail.telepac.pt