Skip to content

ThomasAUB/uxcept

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build status License

uXcept

Lighweight C++17 exception library for microcontrollers.

  • single-header
  • no heap allocation
  • platform independent

Example

#include "uxcept.hpp"

int buffer[3];

void mayFail(uint8_t i, int val) {
    uxcept::assert(i < 3, "invalid index");
    buffer[i] = val;
}

int main() {

    uxcept::tryCatch(
        [&] () {
            mayFail(0, 55);
            mayFail(1, 74);
            mayFail(8, 12);
        },
        [] (std::string_view inError) {
            std::cout << "error : " << inError << std::endl;
        }
    );

    return 0;
}

An error can also be raised using uxcept::raise(error).

Custom error type

Note that it's possible to change the error type that is defaulted to std::string_view. For that, you only need to create a file called "uxcept_error_type.hpp" and define the error type with an alias.

// uxcept_error_type.hpp
namespace uxcept { using error_type = int; }

About

Lighweight C++ exception for microcontrollers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published