mtangoo / wxDatabase

wxWidgets library for connecting to major relational database
http://mtangoo.github.io/database/index.html
36 stars 16 forks source link

Remove Exceptions #18

Open mtangoo opened 8 years ago

mtangoo commented 8 years ago

In wxWidgets coding guidelines exceptions are discouraged. This ticket aim at removing all exceptions in the library.

The idea I have is to have a class similar to QT SQLError. For function that can return bool (like Commit) will do so and for the rest, checking the error it will be something like

wxDatabase *pDatabase =  new wxMysqlDatabase(strServer, strDatabase, strUser, strPassword);
wxSQLError *error = pDatabase->GetLastError();
if(error->GetCode() == 0)
{
    //success
}
else
{
    //unsuccesful
    error->GetText();
    error->GetCode();
}

What do you think @patlkli @manyleaves and whoever reads this ;) ?

manyleaves commented 8 years ago

You already have a class wxDatabaseErrorReporter that more or less does what you describe. My suggestion would be to rename wxDatabaseErrorReporter::ThrowDatabaseException to something like wxDatabaseErrorReporter::LogError and call wxLogError by default or maybe throw an exception within #ifdef #else #endif. Could also rename wxDatabaseErrorReporter! Also, should we complete the map for each wxXYZDatabase::TranslateErrorCode(int nCode) method or continue to pass through the native error codes?

mtangoo commented 8 years ago

You already have a class wxDatabaseErrorReporter that more or less does what you describe. My suggestion would be to rename wxDatabaseErrorReporter::ThrowDatabaseException to something like wxDatabaseErrorReporter::LogError and call wxLogError by default or

Yeah, above suggestion is an abstract. We can reuse the wxDatabaseErrorReporter and just rename it. I have no problem with that. My concern is, user must have a way to know what error happened (code) and the message. So my question was how do we provide for this?

wxLog is okay but then when user want to do something with error (like tell user that libpq.so is missing) is forced to use logging. Some people don't use logging so they will have problem here.

maybe throw an exception within #ifdef #else #endif.

We should avoid having exceptions thrown at all ;)

Could also rename wxDatabaseErrorReporter! Also, should we complete the map for each wxXYZDatabase::TranslateErrorCode(int nCode) method or continue to pass through the native error codes?

I want to hear your opinions on that.

@patlkli what do you think?