# Cpp2 exceptions

**URL:** <https://swi-prolog.discourse.group/t/cpp2-exceptions/6040>\
**Category:** General\
**Created:** [December 20, 2022, 1:06pm UTC](https://swi-prolog.discourse.group/t/cpp2-exceptions/6040 "2022-12-20T13:06:06Z")\
**Posts on this page:** 1\
**Showing post:** 77

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [April 8, 2023, 9:20pm UTC](https://swi-prolog.discourse.group/t/cpp2-exceptions/6040/77 "2023-04-08T21:20:10Z")

</div>

PR is ready for review: [ENHANCED: C++-compatible exception handling + more wrapper functions and classes by kamahen · Pull Request #39 · SWI-Prolog/packages-cpp · GitHub](https://github.com/SWI-Prolog/packages-cpp/pull/39) is ready for review.

Here are the main changes:

- `SWI-cpp2-plx.h` contains wrapper functions (imported from `SWI-cpp2.h`)
- throw `PlException` for Prolog errors
- most `SWI-Prolog.h` functions have a wrapper.
- `verify()` methods removed from `PlAtom`, `PlTerm`, etc.
- the wrapper functions do the checking.
- Some executable code has been moved to `SWI-cpp2.cpp`
- can be inlined, if desired.
- `PlException` is now a subclass of `std::exception`, not a subclass of `PlTerm`.
- `PlTypeError`, `PlDomainError`, etc. are no longer subclasses of `PlTerm`, but are functions for creating suitable PlException objects.
- The string comparison operators are deprecated; use `as_string()` and `std::string` comparison instead, which allows specifying the encoding.
- Added `PlRecord`, `PlRecordExternal`, `PlControl` (used by `PREDICATE_NONDET`), `PlStream`.
- Fixed numerous bugs and misfeatures; added tests.

I’ve also made PRs for swipl-win, rocksdb, and rolog.

I apologize for the large size of the PR, but I didn’t see an easy way to break it into smaller pieces.

The documentation is still a bit rough; I’ll try to review it and improve it “in the future”.

There are still a few things that need to be done, mostly to do with text encodings. However, their lack shouldn’t be a significant issue, and missing functionality should be easy to add.

---

_[View the full topic](https://swi-prolog.discourse.group/t/cpp2-exceptions/6040)._
