2.5.6.3 C++ exceptions and blobs
When a blob is used in the context of a PREDICATE() macro, it can
raise a C++ exception (PlFail or PlException)
and the PREDICATE() code will convert it to the appropriate Prolog
failure or error; memory allocation exceptions are also handled.
Blobs have callbacks, which can run outside the context of a PREDICATE(). Their exception handling is as follows:
- acquire(), which is called from PlBlobV<MyBlob>::acquire(), can throw a C++ exception.
- compare_fields(), which is called from PlBlobV<MyBlob>::compare(), should not throw an exception. A Prolog error won't work as it uses "raw pointers" and thus a GC or stack shift triggered by creating the exception will upset the system.
- write_fields(), which is called from PlBlobV<MyBlob>::write(), can throw an exception, just like code inside a PREDICATE(). In particular, you can wrap calls to Sfprintf() in PlCheckFail(), although the calling context will check for errors on the stream, so checking the Sfprintf() result isn't necessary.
- save() can throw a C++ exception, including PlFail().
- load() can throw a C++ exception, which is converted to a return
value of
PlAtom::null, which is interpreted by Prolog as failure.