Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot catch constraint exception #53

Closed
pakerwreah opened this issue Jun 13, 2016 · 5 comments · Fixed by #54
Closed

Cannot catch constraint exception #53

pakerwreah opened this issue Jun 13, 2016 · 5 comments · Fixed by #54

Comments

@pakerwreah
Copy link

I'm trying to insert a row that produces a primary key constraint failure but the program crashes before I can catch the exception.

try {
db << "INSERT INTO tb_mytable (mytable_id,description) VALUES (?,?)" << 1 << "cannot catch exception";
// inserting again to produce error
db << "INSERT INTO tb_mytable (mytable_id,description) VALUES (?,?)" << 1 << "cannot catch exception";
} catch (exception e)
{
cerr << e.what() << endl;
} catch (...)
{
cerr << "this does not work either" << endl;
}

libc++abi.dylib: terminating with uncaught exception of type sqlite::exceptions::constraint: constraint failed
The program has unexpectedly finished.

@Killili
Copy link
Collaborator

Killili commented Jun 13, 2016

I can confirm that in VS2015. But i cant figure out why....

As soon as the exception is thrown Abort() is getting called as if there where no catch.

@aminroosta
Copy link
Collaborator

@Killili it seems that we are violating library standards! take a look at my SO question

@aminroosta
Copy link
Collaborator

But it seems to me that if we don't use unique_ptr for chain_type then it will no longer be a problem.
typedef std::unique_ptr<sqlite::database_binder> chain_type;

I've spent a couple of hours on this, kind of brain dead now 💀

@Killili
Copy link
Collaborator

Killili commented Jun 13, 2016

Its strange and i can not understand why the standard enforces the no throw rule on unique_ptr even if its allowed/not prohibited in the rest of the standard.
The unique_ptr there is a shortcut to make the prepared statements noncopyable so its not really necessary if we make the database_binder class noncopyable. Other then that i cant think of a reason to not change the chain_type.

@aminroosta
Copy link
Collaborator

@Killili please take a look at #54 and if its ok then merge.
I will create a new release tag, because we have minor breaking changes ppst->reset() becomes ppst.reset().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants