try catch Did not catch the exception

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
xjhwc10
Posts: 4
Joined: Wed 10 Nov 2010 03:21

try catch Did not catch the exception

Post by xjhwc10 » Wed 10 Nov 2010 03:45

I use C++BUILDER6+unidac3.5

try
{
、、、
UQRY->ApplyUpdates();
DM->UTT1->CommitRetaining();
}
catch(EIBCError &e)
{
ShowMessage("aaaaa");


program run and When an error,but Not implemented "ShowMessage("aaaaa");" why?

I want "335544665" this error.

AndreyZ

Post by AndreyZ » Wed 10 Nov 2010 13:27

Hello,

You should catch EUniError instead of EIBCError.

xjhwc10
Posts: 4
Joined: Wed 10 Nov 2010 03:21

Post by xjhwc10 » Wed 10 Nov 2010 14:00

try
{
、、、
UQRY->ApplyUpdates();
DM->UTT1->CommitRetaining();
}
catch(EUniError &e)
{
//use "EUniError &e",Exceptions can be caught,but How to get "GDSCODE",For example:"335544665" this error。
//I use C++BUILDER 6 and firebird 2.1



AndreyZ

Post by AndreyZ » Wed 10 Nov 2010 15:31

UniDAC converts EIBCError to the EUniError exception. You can use the EUniError.InnerError property to get an inner exception like in the following code:

Code: Select all

  try
  {
    UniQuery->ApplyUpdates();
  }
  catch(EUniError &e)
  {
    EIBCError *eribc = static_cast(e.InnerError);
    ShowMessage(IntToStr(eribc->ErrorNumber));
  }

xjhwc10
Posts: 4
Joined: Wed 10 Nov 2010 03:21

Post by xjhwc10 » Wed 17 Nov 2010 09:59

I am sorry ,I made a mistake,
catch(EUniError &e) Can not Exceptions ,catch(Exception &e) can Exceptions,how i can Exception->EDatabaseError->EUniError->EIBCError,get "GDSCODE",For example:"335544665" this error

AndreyZ

Post by AndreyZ » Thu 18 Nov 2010 08:07

The "335544665" error is a violation of the primary or unique keys. You can get this error from the ErrorNumber property of the EIBCError class. Here is an example:

Code: Select all

  try
  {
    UniQuery->Append();
    UniQuery->FieldByName("ID")->AsInteger = 1; // field "ID" is a primary key
    UniQuery->Post();
    UniQuery->Append();
    UniQuery->FieldByName("ID")->AsInteger = 1;
    UniQuery->Post();
    UniQuery->ApplyUpdates();
  }
  catch(EUniError &e)
  {
    EIBCError *eribc = static_cast(e.InnerError);
    ShowMessage(IntToStr(eribc->ErrorNumber)); // here you will see the message "335544665"
  }

Post Reply