Recent

Author Topic: [SOLVED] Problem with try except  (Read 2815 times)

melwinek

  • Jr. Member
  • **
  • Posts: 52
[SOLVED] Problem with try except
« on: April 25, 2015, 10:51:59 am »
I want to handle the exception of duplicate key.

...............
try
  SQL.ExecSQL;
except
   on E: EDatabaseError do
     ShowMessage(E.Message);
end;

First I get my message from ShowMessage.
Then the standard message:
"PQConnection1: Preparation of query failed.........Press OK to ignore and risk data corruption. Press Cancel to kill the program."

How to eliminate standard message?


« Last Edit: April 28, 2015, 11:24:43 am by melwinek »

totya

  • Hero Member
  • *****
  • Posts: 577
Re: Problem with try except
« Reply #1 on: April 25, 2015, 11:18:46 am »
Code: [Select]
try
  SQL.ExecSQL;
except
   on E: EDatabaseError do ShowMessage(E.Message);
   on E: Exception do; // if you want to hide this error message really...
end;

LacaK

  • Hero Member
  • *****
  • Posts: 577
Re: Problem with try except
« Reply #2 on: April 25, 2015, 05:43:21 pm »
EPQDatabaseError which is raised by TPQConnection is descendant of EDatabaseError, so it should be handled by:
  on E: EDatabaseError do

I do not understand why error message is displayed twice:
- first by ShowMessage
- second standard error handling

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Problem with try except
« Reply #3 on: April 25, 2015, 06:56:30 pm »
Sample project required. Exception that has been handled won't return. i.e. if EDatabaseError (or its descendants) is raised by ExecSQL and handled by on e: EDatabaseError, then after that, normal program flow continues. The second one must be triggered by another thing, could be the same method, I don't know as I can't see the complete code.

melwinek

  • Jr. Member
  • **
  • Posts: 52
Re: Problem with try except
« Reply #4 on: April 28, 2015, 11:24:16 am »
Code: [Select]
try
  SQL.ExecSQL;
except
   on E: EDatabaseError do ShowMessage(E.Message);
   on E: Exception do; // if you want to hide this error message really...
end;

Thank you very much.
It works.