soci icon indicating copy to clipboard operation
soci copied to clipboard

Oracle - can't catch exception

Open Adiqq opened this issue 7 years ago • 11 comments

I'm using Oracle, with GCC/C++17 and SOCI build from master. Probably related to https://github.com/SOCI/soci/issues/256

Calling below function:

bool Store::AddUser(User user){
    // if(users.count(user.Login) > 0){
    //     return false;
    // }
    // users[user.Login] = user;
    // return true;
    try{
        std::cout << "login: " << user.Id << std::endl;
        std::cout << "password: " << user.HashedPassword << std::endl;
        session.sql << "INSERT INTO users(id, hashedpassword,salt) VALUES(:id, :hashedpassword, :salt)", use(user.Id), use(user.HashedPassword), use(user.Salt);
        return true;
    }
    catch (soci::oracle_soci_error const & e)
    {
        std::cerr << e.what() << std::endl;
        return false;
    }
    catch (...)
    {
        std::cerr << "Some other error: " << std::endl;
        return false;
    }
}

Results in crash:

terminate called after throwing an instance of 'soci::oracle_soci_error'
  what():  ORA-00001: unique constraint (SYSTEM.USER_PK) violated
 while executing

Adiqq avatar Jan 17 '18 16:01 Adiqq

soci is compiled by default with -std=gnu++98 on gcc. You can force SOCI_CXX_C11 to ON in your cmake file to allow exceptions in the soci::details::once_temp_type::~once_temp_type destructor. Otherwise in your case std::terminate is called.

I had the same problem. Enable C++11 by default seems a good thing. What do you think @mloskot?

Wescoeur avatar Feb 12 '18 15:02 Wescoeur

@Adiqq @Wescoeur Could you please provide version you're using? Thank you.

snikulov avatar Feb 12 '18 15:02 snikulov

No problem, the master branch.

Wescoeur avatar Feb 12 '18 15:02 Wescoeur

Master branch as well. So something like cmake -G "Unix Makefiles" -DWITH_BOOST=ON -DWITH_ORACLE=ON -DSOCI_CXX_C11=ON . should fix it? I was just playing around with SOCI for university project and this issue was troublesome, so it would be nice to at least mention about this flag in documentation.

Adiqq avatar Feb 12 '18 18:02 Adiqq

@Adiqq Thanks for spotting SOCI_CXX_C11 is missing from the docs. It should be there now. See the latest here http://soci.sourceforge.net/doc/master/installation/ (auto-generated on every commit).

@Wescoeur C++11 by default has been discussed a few times and the overall consensus was

  • we don't want to require C++11 (or later)
  • we want to allow C++11 (or later)

This may change in future though.

mloskot avatar Feb 12 '18 20:02 mloskot

mysql insert a record that already exists soci::mysql_soci_error not receive an exception Error SIGABRT (Aborted) soci commit f4927b27a cmake -G "Unix Makefiles" -DWITH_BOOST=ON -DWITH_MYSQL=ON -DSOCI_CXX_C11=ON .. mysql v5.7

rise-worlds avatar May 25 '18 06:05 rise-worlds

@rise-worlds such incomplete nonsense makes useless issue reports

mloskot avatar May 25 '18 07:05 mloskot

Why SOCI_CXX_C11? You should use CMAKE_CXX_STANDARD

5cript avatar Sep 19 '19 20:09 5cript

@5cript because of

https://github.com/SOCI/soci/blob/601a89227d844e279fae3edfde85739067d382b3/CMakeLists.txt#L13

mloskot avatar Sep 19 '19 20:09 mloskot

And what about optionally checking against __cplusplus if existant/supported, secondarily using the special soci cmake option? In principal this allows for CMAKE_CXX_STANDARD where supported.

5cript avatar Sep 20 '19 06:09 5cript

@5cript I moved the discussion to specific thread in #752

mloskot avatar Sep 20 '19 07:09 mloskot