ErrorHandling#

class numpy::ErrorHandling#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use ErrorHandling
ErrorHandling obj;
// ... operations ...

Indexing / Selection#

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#

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

View

void set_buffer_size(size_tsize)

void

NP_ERROR_HANDLING.H:135

void set_error_callback(std::function<void(const std::string&)>callback)

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.

handle_error (np_test_2_all.cpp:19467)
19457        callback_message = msg;
19458        };
19459
19460      // Set callback
19461      auto old_callback = numpy::config::seterrcall(callback);
19462
19463      // Set mode to "call"
19464      auto old_state = numpy::config::seterr("call", "", "", "");
19465
19466      // Trigger error
19467      numpy::config::ErrorHandling::handle_error("divide", "Test error message");
19468
19469      if (!callback_called) {
19470        std::cout << "  [FAIL] : Callback was not called";
19471        throw std::runtime_error("np_test_error_callback failed: not called");
19472      }
19473
19474      if (callback_message != "Test error message") {
19475        std::cout << "  [FAIL] : Callback message incorrect";
19476        throw std::runtime_error("np_test_error_callback failed: message");
19477      }