Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 653 Bytes

error_handling.md

File metadata and controls

28 lines (22 loc) · 653 Bytes

Error Handling

With C++ Exception

When C++ exception is enabled, throw naah::{Error, RangeError, TypeError} directly in your C++ code.

uint32_t TestNum(uint32_t num) {
  if (num < 10) {
    throw naah::RangeError("num too small");
  }
  return num - 10;
}

Without C++ Exception

When C++ exception is disabled, use naah::Result<T, E> as return value, where E is one of naah::Error, naah::TypeError or naah::RangeError.

naah::Result<std::string, naah::RangeError> FunctionThrowsWithResult(
    uint32_t i) {
  if (i > 233) {
    return naah::RangeError("bigger than 233");
  }
  return std::to_string(i);
}