Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Catching Excetion Error



Permlink Replies: 6 - Last Post: Nov 10, 2017 11:27 AM Last Post By: Bob Gambler
Bob Gambler

Posts: 61
Registered: 8/23/10
Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 12:47 PM
I would like to cacth the error in ShowMessage line, but the system prompt a message error and never execute that line. What is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' + FDQuery1.RowsAffected.ToString);
   Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); // Dont works
      End;
   End;
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 1:28 PM   in response to: Bob Gambler in response to: Bob Gambler
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the system prompt a message error and never execute that line. What is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' + FDQuery1.RowsAffected.ToString);
   Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); // Dont works
      End;
   End;

Probably just means the exception being raised is not that class of exception.

Just add a second On e : Exception and show both the message and the classname
of the exception so you can better catch the explicate exception being raised.


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Bob Gambler

Posts: 61
Registered: 8/23/10
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 6:26 PM   in response to: Jeff Overcash (... in response to: Jeff Overcash (...
Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the system prompt a message error and never execute that line. What is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' + FDQuery1.RowsAffected.ToString);
   Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); // Dont works
      End;
   End;

Probably just means the exception being raised is not that class of exception.

Just add a second On e : Exception and show both the message and the classname
of the exception so you can better catch the explicate exception being raised.


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)


Memo1.text contains, for example, an update to an nonexistent table and a corresponding message is promped from Firedac. In docwiki from Embarcadero(http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Handling_Errors_(FireDAC)), that approach seems like a general pourpose exception cacth to FireDAC. Maybe i`m missing something. Can you explain better?

Tks
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 8:40 PM   in response to: Bob Gambler in response to: Bob Gambler
Bob Gambler wrote:

Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the
system prompt a message error and never execute that line. What
is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);    Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); //
Dont works       End;
   End;
[ snip]

Memo1.text contains, for example, an update to an nonexistent table
and a corresponding message is promped from Firedac. In docwiki from
Embarcadero(http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Handling
_Errors_(FireDAC)), that approach seems like a general pourpose
exception cacth to FireDAC. Maybe i`m missing something. Can you
explain better?

Tks

You could use a break point or catch every exception and inspect the
raised exeption class, like:

{code}

FDQuery1.SQL.Add(Memo1.Text);
Try
FDQuery1.ExecSQL();
ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);
Except
On E:EFDDBEngineException do
Begin
ShowMessage('Query`s Execution Error' + E.Message);
End;
on e: exception do
Begin
ShowMessage(E.Classname+':Query`s Execution Error' +
E.Message);
End;
End;

With this code you can find out the exception class raised.
Bob Gambler

Posts: 61
Registered: 8/23/10
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2017 7:25 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:
Bob Gambler wrote:

Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the
system prompt a message error and never execute that line. What
is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);    Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); //
Dont works       End;
   End;
[ snip]

Memo1.text contains, for example, an update to an nonexistent table
and a corresponding message is promped from Firedac. In docwiki from
Embarcadero(http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Handling
_Errors_(FireDAC)), that approach seems like a general pourpose
exception cacth to FireDAC. Maybe i`m missing something. Can you
explain better?

Tks

You could use a break point or catch every exception and inspect the
raised exeption class, like:

{code}

FDQuery1.SQL.Add(Memo1.Text);
Try
FDQuery1.ExecSQL();
ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);
Except
On E:EFDDBEngineException do
Begin
ShowMessage('Query`s Execution Error' + E.Message);
End;
on e: exception do
Begin
ShowMessage(E.Classname+':Query`s Execution Error' +
E.Message);
End;
End;

With this code you can find out the exception class raised.

No ShowMessage executed.

My goal would be just to catch the Firedac errors. It seemed to me that the code shown on the wiki would work fine.
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2017 10:50 AM   in response to: Bob Gambler in response to: Bob Gambler
Bob Gambler wrote:
Lajos Juhasz wrote:
Bob Gambler wrote:

Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the
system prompt a message error and never execute that line. What
is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);    Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); //
Dont works       End;
   End;
[ snip]

Memo1.text contains, for example, an update to an nonexistent table
and a corresponding message is promped from Firedac. In docwiki from
Embarcadero(http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Handling
_Errors_(FireDAC)), that approach seems like a general pourpose
exception cacth to FireDAC. Maybe i`m missing something. Can you
explain better?

Tks
You could use a break point or catch every exception and inspect the
raised exeption class, like:

{code}

FDQuery1.SQL.Add(Memo1.Text);
Try
FDQuery1.ExecSQL();
ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);
Except
On E:EFDDBEngineException do
Begin
ShowMessage('Query`s Execution Error' + E.Message);
End;
on e: exception do
Begin
ShowMessage(E.Classname+':Query`s Execution Error' +
E.Message);
End;
End;

With this code you can find out the exception class raised.

No ShowMessage executed.

My goal would be just to catch the Firedac errors. It seemed to me that the code shown on the wiki would work fine.

Are you certain that you are not just seeing the IDE catch the exception? When
debugging the IDE will show the exception first and break execution. Then when
you continue it is possible that FD is handling the exception which is why it
never escapes the FD code to get to your exception handler.

FDQuery has an OnError event that passes you the exception on the event of an
error during ExecSQL so I suspect that what is happening is you are seeing the
debugger's first level handling of the exception, you are continuing and FD is
handling the exception, passing it to OnError (if assigned) and therefore the
exception is never raised back to your level of code.

http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.Client.TFDRdbmsDataSet.OnError


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Bob Gambler

Posts: 61
Registered: 8/23/10
Re: Catching Excetion Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2017 11:27 AM   in response to: Jeff Overcash (... in response to: Jeff Overcash (...
Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
Lajos Juhasz wrote:
Bob Gambler wrote:

Jeff Overcash (TeamB) wrote:
Bob Gambler wrote:
I would like to cacth the error in ShowMessage line, but the
system prompt a message error and never execute that line. What
is wrong?

Tks

   FDQuery1.SQL.Add(Memo1.Text);
 
   Try
      FDQuery1.ExecSQL();
      ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);    Except
      On E:EFDDBEngineException do
      Begin
         ShowMessage('Query`s Execution Error' + E.Message); //
Dont works       End;
   End;
[ snip]

Memo1.text contains, for example, an update to an nonexistent table
and a corresponding message is promped from Firedac. In docwiki from
Embarcadero(http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Handling
_Errors_(FireDAC)), that approach seems like a general pourpose
exception cacth to FireDAC. Maybe i`m missing something. Can you
explain better?

Tks
You could use a break point or catch every exception and inspect the
raised exeption class, like:

{code}

FDQuery1.SQL.Add(Memo1.Text);
Try
FDQuery1.ExecSQL();
ShowMessage('Affected Rows: ' +
FDQuery1.RowsAffected.ToString);
Except
On E:EFDDBEngineException do
Begin
ShowMessage('Query`s Execution Error' + E.Message);
End;
on e: exception do
Begin
ShowMessage(E.Classname+':Query`s Execution Error' +
E.Message);
End;
End;

With this code you can find out the exception class raised.

No ShowMessage executed.

My goal would be just to catch the Firedac errors. It seemed to me that the code shown on the wiki would work fine.

Are you certain that you are not just seeing the IDE catch the exception? When
debugging the IDE will show the exception first and break execution. Then when
you continue it is possible that FD is handling the exception which is why it
never escapes the FD code to get to your exception handler.

FDQuery has an OnError event that passes you the exception on the event of an
error during ExecSQL so I suspect that what is happening is you are seeing the
debugger's first level handling of the exception, you are continuing and FD is
handling the exception, passing it to OnError (if assigned) and therefore the
exception is never raised back to your level of code.

http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.Client.TFDRdbmsDataSet.OnError


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)


Right on the target. Thanks Mr Overcash.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02