Comments (10)
Just in case you still need this: I created a PoC (zauguin/errorcodes) where the exception object contains a get_code()
method to access the code.
But I do not think that this is generally useful. Why do you want to catch sqlite_exception and use a switch instead of catching the individual error types?
from sqlite_modern_cpp.
Actually the old changing was API-breaking already, because you had to pass the errorcode.
So I pushed a change which adds this as a second constructor.
from sqlite_modern_cpp.
An IMHO cleaner (but API-breaking) change would be to change the sqlite_exception constructor to something like:
sqlite_exception(char ecode): runtime_error(sqlite3_errstr(ecode)), code(ecode) {}
Which would allow the specific exceptions to be initialized by (i.e.):
if(error_code == SQLITE_ERROR) throw exceptions::error(error_code);
instead of:
if(error_code == SQLITE_ERROR) throw exceptions::error(sqlite3_errstr(error_code), error_code);
But perhaps that's too disruptive for just the sake of looking better.
from sqlite_modern_cpp.
The error code can't be a accessed directly, you can differentiate the errors by the type and the message.
Why do you need the codes?
from sqlite_modern_cpp.
Hmm, you have made row id available, surly its straight forward to make the error_code available?
When I catch-all exceptions using sqlite_exception, using error_code I could have a simple switch statement.
How is type available in the catch-all sqlite_exception?
from sqlite_modern_cpp.
Unless I'm missing something the sqlite_exception is a struct that contains a string. It would be of great help
to have the struct also contain the error code ... :)
from sqlite_modern_cpp.
Thanks ... I used your earlier suggestion and used typeid(object) instead. For all exceptions I need to just log the error and no_row I need to do a little extra processing. It's been a long day!
from sqlite_modern_cpp.
Having thought about this I think using get_code() is cleaner. Using typeid(e) seems to me to be a cludge to get the information.
I hope you merge this into master :)
from sqlite_modern_cpp.
@aminroosta What do you think about this?
from sqlite_modern_cpp.
Looks good to me, Thanks @zauguin!
Can you write a little documentation in the README file :-)
from sqlite_modern_cpp.
Related Issues (20)
- typo in the std::variant<std::string, ...> supprt HOT 1
- std::optional and std::variant not supported with MSVC 2019 HOT 4
- unnecessary calls to sqlite3_{column,value}_bytes{,16} in getting text HOT 4
- ability to change database name HOT 1
- Ability to interrupt queries
- Does this library support the JSON1 extension? HOT 1
- Usage of `std::optional` fails under MSVC 14.2 / VS 2019 HOT 2
- How to get a binary blob and it's size HOT 1
- about latest release HOT 2
- I dont know how to compile my C++ files with this library HOT 2
- [question] about data update wrapper HOT 2
- with C++20 HOT 1
- Serialized Mode of Sqlite3
- Invalid range expression of type 'database_binder'; no viable 'begin' function available HOT 3
- Are JOIN operations suported? HOT 1
- Set `std::optional` to `std::nullopt` instead of throwing `sqlite::errors::no_rows`
- Project does not work in VS2022 HOT 1
- Unknown number of columns HOT 1
- Database encryption HOT 1
- Possible to use via FetchContent or CPM? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite_modern_cpp.