vendredi 28 juillet 2017

Beginner C++ - Trying to catch an exception

So basically I have this code:

#include <iostream>
using namespace std;

#include "libsqlite.hpp"

int main()
{
    sqlite::sqlite db( "firefly.sqlite" );

    auto cur = db.get_statement(); 

    // cur->set_sql( "CREATE TABLE students_mark (sid INT, name VARCHAR(255), pt1_mark INT, pt2_mark INT, cw_mark INT, PRIMARY KEY(sid, name));" );
    cur->set_sql( "INSERT INTO students_mark (sid, name, pt1_mark, pt2_mark, cw_mark) VALUES (?, ?, ?, ?, ?);" );

    cur->prepare();
}

Which gives me this error:

libc++abi.dylib: terminating with uncaught exception of type sqlite::exception: std::exception
Abort trap: 6

So I tried to catch the exception to understand it better, but I can't seem to archieve this goal.

Here's what I did:

try {
    cur->prepare();
} catch(exception& e) {
    cout << "Error: " << e.what() << endl;
}

and this gives me this output: Error: std::exception

What can I do?

Thanks a lot

Aucun commentaire:

Enregistrer un commentaire