-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from zauguin/uncaught_exceptions
Use std::uncaught_exceptions if possible
- Loading branch information
Showing
6 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
#include <exception> | ||
#include <iostream> | ||
|
||
namespace sqlite { | ||
namespace utility { | ||
#ifdef __cpp_lib_uncaught_exceptions | ||
class UncaughtExceptionDetector { | ||
public: | ||
operator bool() { | ||
return count != std::uncaught_exceptions(); | ||
} | ||
private: | ||
int count = std::uncaught_exceptions(); | ||
}; | ||
#else | ||
class UncaughtExceptionDetector { | ||
public: | ||
operator bool() { | ||
return std::uncaught_exception(); | ||
} | ||
}; | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <sqlite_modern_cpp.h> | ||
using namespace sqlite; | ||
using namespace std; | ||
|
||
|
||
int main() { | ||
database db(":memory:"); | ||
db << "CREATE TABLE person (id integer primary key not null, name TEXT not null);"; | ||
|
||
try { | ||
auto stmt = db << "INSERT INTO person (id,name) VALUES (?,?)"; | ||
throw 1; | ||
} catch (int) { | ||
} | ||
exit(EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <sqlite_modern_cpp.h> | ||
using namespace sqlite; | ||
using namespace std; | ||
|
||
struct A { | ||
~A() { | ||
database db(":memory:"); | ||
db << "CREATE TABLE person (id integer primary key not null, name TEXT not null);"; | ||
|
||
try { | ||
auto stmt = db << "INSERT INTO person (id,name) VALUES (?,?)"; | ||
throw 1; | ||
} catch (int) { | ||
} | ||
} | ||
}; | ||
int main() { | ||
#ifdef __cpp_lib_uncaught_exceptions | ||
try { | ||
A a; | ||
throw 1; | ||
} catch(int) { | ||
} | ||
exit(EXIT_SUCCESS); | ||
#else | ||
exit(42); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters