ErrorHandling ============= .. cpp:class:: numpy::ErrorHandling numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use ErrorHandling ErrorHandling obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t get_buffer_size()`` - size_t - NP_ERROR_HANDLING.H:129 - * - ``ErrorState get_error_state()`` - ErrorState - NP_ERROR_HANDLING.H:86 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void clear_thread_error_state()`` - void - NP_ERROR_HANDLING.H:109 - * - ``void handle_error(const std::string &error_type, const std::string &message)`` - void - NP_ERROR_HANDLING.H:141 - :ref:`View ` * - ``void set_buffer_size(size_tsize)`` - void - NP_ERROR_HANDLING.H:135 - * - ``void set_error_callback(std::functioncallback)`` - void - NP_ERROR_HANDLING.H:123 - * - ``void set_error_state(const ErrorState &state)`` - void - NP_ERROR_HANDLING.H:95 - * - ``void set_thread_error_state(const ErrorState &state)`` - void - NP_ERROR_HANDLING.H:101 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-errorhandling-handle_error-0: .. dropdown:: handle_error (np_test_2_all.cpp:19467) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19457 :emphasize-lines: 11 callback_message = msg; }; // Set callback auto old_callback = numpy::config::seterrcall(callback); // Set mode to "call" auto old_state = numpy::config::seterr("call", "", "", ""); // Trigger error numpy::config::ErrorHandling::handle_error("divide", "Test error message"); if (!callback_called) { std::cout << " [FAIL] : Callback was not called"; throw std::runtime_error("np_test_error_callback failed: not called"); } if (callback_message != "Test error message") { std::cout << " [FAIL] : Callback message incorrect"; throw std::runtime_error("np_test_error_callback failed: message"); }