File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -402,6 +402,30 @@ Additionally you can use `get_sql()` to see the SQL statement leading to the err
402
402
catch(sqlite::errors::constraint_primarykey e) { } */
403
403
```
404
404
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
+
405
429
Custom SQL functions
406
430
----
407
431
You can’t perform that action at this time.
0 commit comments