Page 1 of 1
how to catch a exception from TMyCommand
Posted: Fri 05 Aug 2005 12:30
by mikrodidakt
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.

Posted: Fri 05 Aug 2005 13:31
by mikrodidakt
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

Posted: Fri 05 Aug 2005 15:56
by Ikar
Use EMyError instead of EMySqlException
Posted: Sun 07 Aug 2005 15:50
by mikrodidakt
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

Posted: Sun 07 Aug 2005 17:31
by mikrodidakt
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

Posted: Mon 08 Aug 2005 07:28
by Paul
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.
Posted: Mon 08 Aug 2005 07:55
by Guest
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";
}
Posted: Mon 08 Aug 2005 09:10
by mikrodidakt
sorry my misstake ignore the message above, i forgotte to log in so the guest above is me.

Posted: Mon 08 Aug 2005 09:16
by mikrodidakt
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
