how to catch a exception from TMyCommand

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

how to catch a exception from TMyCommand

Post by mikrodidakt » Fri 05 Aug 2005 12:30

hi
this is the code:

__fastcall TMySQLForm::TMySQLForm(TComponent* Owner)
: TForm(Owner)
{
try
{
MySQLModule->MyCommand->Execute(1);
}
catch (const EMySqlException &E)
{
this->SerchOpComboBox->Text = "error";
}
}
this is the error:
[C++ Error] MySQLMain.cpp(36): E2377 Catch statement missing )

I dont know if this is the correct way to catch a EMySqlException or not. :?:
Last edited by mikrodidakt on Fri 05 Aug 2005 13:34, edited 1 time in total.

mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

Post by mikrodidakt » Fri 05 Aug 2005 13:31

Stupid me i forgot to include MySqlErrors.hpp
but now i get this

[C++ Error] MySqlErrors.hpp(43): E2238 Multiple declaration for '_fastcall EMySqlException::EMySqlException(int)'
[C++ Error] MySqlErrors.hpp(35): E2344 Earlier declaration of '_fastcall EMySqlException::EMySqlException(int)'

whats up with that :?: :?: :?: :?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 05 Aug 2005 15:56

Use EMyError instead of EMySqlException

mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

Post by mikrodidakt » Sun 07 Aug 2005 15:50

what hpp file should i include then because when i am using EMyError or EMySqlException it never jumps to catch, so it seems like the exception is caught some where else. the cod that i have used is

Code: Select all

try
{
    MySQLModule->MyCommand->Execute(1);
}//the message is printed here  
catch (const EMyError &e)
{
    this->SerchOpComboBox->Text = "error";
}
is this correct :?:

mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

Post by mikrodidakt » Sun 07 Aug 2005 17:31

If one of the MySQL Access components is catching a exception is the exception rethrow or do i have to do some settings to make it rethrow the exception :?:

Paul
Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Mon 08 Aug 2005 07:28

EMyError is defined in MyClasses.hpp. You can include MyAccess.hpp file only.
Your code is correct. I can receive exception if I write invalide SQL to MyCommand.
No component hides execption inside. You can see it in your try-catch block.

Guest

Post by Guest » Mon 08 Aug 2005 07:55

Hi, thanks

I get a error now:
[C++ Error] MySQLMain.cpp(465): E2377 Catch statement missing )
which I interpreter as it does´t know MyError i have done the settings for
the project so the path to MyDac/include is set.
I tried to include both MyAccess.hpp and MyClasses.hpp but it did not work.

Code: Select all

  try
  {
    MySQLModule->MyCommand->Execute(1);
  }
  catch (const MyError &e)
  {
    this->SerchOpComboBox->Text = "error";
  }

mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

Post by mikrodidakt » Mon 08 Aug 2005 09:10

sorry my misstake ignore the message above, i forgotte to log in so the guest above is me. :lol:

mikrodidakt
Posts: 20
Joined: Fri 05 Aug 2005 12:20
Location: Sweden

Post by mikrodidakt » Mon 08 Aug 2005 09:16

Code: Select all

try
  {
    AnsiString sqlStr = "use temp2;";
    MySQLModule->MyCommand->SQL->Clear();
    MySQLModule->MyCommand->SQL->Text = sqlStr;
    MySQLModule->MyCommand->Execute(1);
  }
  catch (const EMyError &e)
  {
    this->SerchOpComboBox->Text = "error";
  }

there is no database named temp2 so a EMySqlException is thrown but
the exception is not caught it never gets to the catch statment :?: :?:

Post Reply