Skip to content

Latest commit

 

History

History
118 lines (93 loc) · 4.22 KB

tutorial_errors.rst

File metadata and controls

118 lines (93 loc) · 4.22 KB

Error Handling

Conduit's APIs emit three types of messages for logging and error handling:

Message Type Description
Info

General Information

Warning

Recoverable Error

Error

Fatal Error

Default Error Handlers

Conduit provides a default handler for each message type:

Message Type Default Action
Info

Prints the message to standard out

Warning

Throws a C++ Exception (conduit::Error instance)

Error

Throws a C++ Exception (conduit::Error instance)

Using Custom Error Handlers

The conduit::utils namespace provides functions to override each of the three default handlers with a method that provides the following signature:

void my_handler(const std::string &msg,
                const std::string &file,
                int line)
{
  // your handling code here ...
}

conduit::utils::set_error_handler(my_handler);

Here is an example that re-wires all three error handlers to print to standard out:

../../tests/docs/t_conduit_docs_tutorial_examples.cpp

../../tests/docs/t_conduit_docs_tutorial_examples.cpp

t_conduit_docs_tutorial_examples_out.txt

Using Restoring Default Handlers

The default handlers are part of the conduit::utils interface, so you can restore them using:

../../tests/docs/t_conduit_docs_tutorial_examples.cpp