Page 1 of 1

try catch Did not catch the exception

Posted: Wed 10 Nov 2010 03:45
by xjhwc10
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.

Posted: Wed 10 Nov 2010 13:27
by AndreyZ
Hello,

You should catch EUniError instead of EIBCError.

Posted: Wed 10 Nov 2010 14:00
by xjhwc10
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



Posted: Wed 10 Nov 2010 15:31
by AndreyZ
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));
  }

Posted: Wed 17 Nov 2010 09:59
by xjhwc10
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

Posted: Thu 18 Nov 2010 08:07
by AndreyZ
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"
  }