Skip to content

Commit 2f8061f

Browse files
committed
Add documentation
1 parent 7271dff commit 2f8061f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,30 @@ Additionally you can use `get_sql()` to see the SQL statement leading to the err
402402
catch(sqlite::errors::constraint_primarykey e) { } */
403403
```
404404
405+
You can also register a error logging function with `sqlite::error_log`.
406+
The `<sqlite_modern_cpp/log.h>` header has to be included to make this function available.
407+
The call to `sqlite::error_log` has to be the first call to any `sqlite_modern_cpp` function by your program.
408+
409+
```c++
410+
error_log(
411+
[&](sqlite_exception& e) {
412+
cerr << e.get_code() << ": " << e.what() << endl;
413+
},
414+
[&](errors::misuse& e) {
415+
/* You can behave differently to specific exceptions */
416+
}
417+
);
418+
database db(":memory:");
419+
db << "create table person (id integer primary key not null, name text);";
420+
421+
try {
422+
db << "insert into person (id, name) values (?,?)" << 1 << "jack";
423+
// inserting again to produce error
424+
db << "insert into person (id, name) values (?,?)" << 1 << "jack";
425+
}
426+
catch (sqlite_exception& e) {}
427+
```
428+
405429
Custom SQL functions
406430
----
407431

0 commit comments

Comments
 (0)