Skip to content

Latest commit

 

History

History
99 lines (69 loc) · 3.39 KB

tutorial_cpp_errors.rst

File metadata and controls

99 lines (69 loc) · 3.39 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_errors.cpp

../../tests/docs/t_conduit_docs_tutorial_errors.cpp

t_conduit_docs_tutorial_errors_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_errors.cpp

Accessing Current Handlers

You can access the currently active handlers using the conduit::utils::info_handler(), conduit::utils::warning_handler(), and conduit::utils::error_handler() methods. Here is an example that shows how to save the current handlers, temporarily restore the default handlers, execute an operation, and finally restore the saved handlers:

../../tests/docs/t_conduit_docs_tutorial_errors.cpp