PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
Exceptions

Possible exceptions that could be thrown by the libpmemobj++. More...

Classes

class  pmem::pool_error
 Custom pool error class. More...
 
class  pmem::pool_invalid_argument
 Custom pool error class. More...
 
class  pmem::transaction_error
 Custom transaction error class. More...
 
class  pmem::lock_error
 Custom lock error class. More...
 
class  pmem::transaction_alloc_error
 Custom transaction error class. More...
 
class  pmem::transaction_out_of_memory
 Custom out of memory error class. More...
 
class  pmem::transaction_free_error
 Custom transaction error class. More...
 
class  pmem::transaction_scope_error
 Custom transaction error class. More...
 
class  pmem::manual_tx_abort
 Custom transaction error class. More...
 
class  pmem::layout_error
 Custom layout error class. More...
 
class  pmem::ctl_error
 Custom ctl error class. More...
 
class  pmem::defrag_error
 Custom defrag error class. More...
 

Detailed Description

Possible exceptions that could be thrown by the libpmemobj++.

In runtime, some operations may fail, then all you need is to catch the exception. Every pmem exception has std::runtime_error in its inheritance tree, which means that all exceptions can be caught using just this type. Each exception contains proper message with an error description.

Look at the list on this page to explore all exceptions with their descriptions.

Transaction handles uncaught exceptions thrown inside its scope, then aborts and rethrow the previous exception. That way you never loose the original exception and at the same time, the transaction state is handled properly by the library.

Let's consider following example:

int
main(int argc, char *argv[])
{
if (argc < 2) {
show_usage(argv);
return 1;
}
const char *path = argv[1];
static constexpr size_t QUEUE_SIZE = 1000;
try {
pop = pmem::obj::pool<root>::open(path, "mpsc_queue");
if (pop.root()->log == nullptr) {
pmem_log_type>(QUEUE_SIZE);
});
}
single_threaded(pop);
} catch (pmem::pool_error &e) {
std::cerr << e.what() << std::endl;
std::cerr
<< "To create pool run: pmempool create obj --layout=mpsc_queue -s 100M path_to_pool"
<< std::endl;
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
}
try {
pop.close();
} catch (const std::logic_error &e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:676
Persistent memory aware implementation of multi producer single consumer queue.
Definition: mpsc_queue.hpp:52
void close()
Closes the pool.
Definition: pool.hpp:256
PMEMobj pool class.
Definition: pool.hpp:482
static pool< T > open(const std::string &path, const std::string &layout)
Opens an existing object store memory pool.
Definition: pool.hpp:672
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:644
Custom pool error class.
Definition: pexceptions.hpp:84
detail::pp_if_not_array< T >::type make_persistent(allocation_flag flag, Args &&... args)
Transactionally allocate and construct an object of type T.
Definition: make_persistent.hpp:54

There are plenty of try-catch blocks placed to handle possible errors that can occur in some conditions. E.g. pmem::obj::pool<T>::open can lead to pmem::pool_error. The next exception, std::exception, is placed to handle possible errors during allocation, coming from pmem::obj::make_persistent. Worth being careful using any new function because some exceptions are not obvious, e.g., pmem::obj::pool<T>::close at the end of the code, which may throw std::logic_error.

You should check every function you will use in the context of possible exceptions and then handle them to avoid a crash.