Git Product home page Git Product logo

Comments (10)

zauguin avatar zauguin commented on June 10, 2024 2

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.

zauguin avatar zauguin commented on June 10, 2024 2

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.

polesapart avatar polesapart commented on June 10, 2024 1

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.

zauguin avatar zauguin commented on June 10, 2024

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.

mtissington avatar mtissington commented on June 10, 2024

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.

mtissington avatar mtissington commented on June 10, 2024

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.

mtissington avatar mtissington commented on June 10, 2024

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.

mtissington avatar mtissington commented on June 10, 2024

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.

zauguin avatar zauguin commented on June 10, 2024

@aminroosta What do you think about this?

from sqlite_modern_cpp.

aminroosta avatar aminroosta commented on June 10, 2024

Looks good to me, Thanks @zauguin!
Can you write a little documentation in the README file :-)

from sqlite_modern_cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.