• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

2.5.6 Blobs
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 2)
          • Overview (version 2)
            • Blobs
              • How to define a blob using C++
              • The life of a PlBlob
              • C++ exceptions and blobs
              • Sample PlBlob code
              • Discussion of the sample PlBlob code
              • Identifying blobs by atoms

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.

ClioPatria (version V3.1.1-48-gf653ce4)