Skip to content

Commit

Permalink
Make dtors not throw exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwongu committed May 3, 2016
1 parent 9bb847a commit aa23baa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions headeronly_src/sqlite3pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace sqlite3pp

protected:
explicit statement(database& db, char const* stmt = nullptr);
~statement() noexcept(false);
~statement();

int prepare_impl(char const* stmt);
int finish_impl(sqlite3_stmt* stmt);
Expand Down Expand Up @@ -311,7 +311,7 @@ namespace sqlite3pp
{
public:
explicit transaction(database& db, bool fcommit = false, bool freserve = false);
~transaction() noexcept(false);
~transaction();

int commit();
int rollback();
Expand Down
17 changes: 9 additions & 8 deletions headeronly_src/sqlite3pp.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ namespace sqlite3pp
}
}

inline statement::~statement() noexcept(false)
inline statement::~statement()
{
auto rc = finish();
if (rc != SQLITE_OK)
throw database_error(db_);
// finish() can return error. If you want to check the error, call
// finish() explicitly before this object is destructed.
finish();
}

inline int statement::prepare(char const* stmt)
Expand Down Expand Up @@ -550,12 +550,13 @@ namespace sqlite3pp
throw database_error(*db_);
}

inline transaction::~transaction() noexcept(false)
inline transaction::~transaction()
{
if (db_) {
auto rc = db_->execute(fcommit_ ? "COMMIT" : "ROLLBACK");
if (rc != SQLITE_OK)
throw database_error(*db_);
// execute() can return error. If you want to check the error,
// call commit() or rollback() explicitly before this object is
// destructed.
db_->execute(fcommit_ ? "COMMIT" : "ROLLBACK");
}
}

Expand Down

0 comments on commit aa23baa

Please sign in to comment.