Actually call on_reset callback
[lsnes.git] / include / library / exrethrow.hpp
blob7cae838df85ef50f11b0ca50ab0c143b3380f50c
1 #ifndef _library__exrethrow__hpp__included__
2 #define _library__exrethrow__hpp__included__
4 #include <stdexcept>
5 #include <functional>
7 namespace exrethrow
9 /**
10 * Add a exception type.
12 void add_ex_spec(unsigned prio, std::function<bool(std::exception& e)> identify,
13 std::function<void()> (*throwfn)(std::exception& e));
14 std::function<void()> get_throw_fn(std::exception& e);
16 /**
17 * Exception type specifier.
19 template<typename T, unsigned prio> class ex_spec
21 public:
22 ex_spec()
24 add_ex_spec(prio, [](std::exception& e) -> bool { return (dynamic_cast<T*>(&e) != NULL); },
25 [](std::exception& e) -> std::function<void()> { T _ex = *dynamic_cast<T*>(&e);
26 return [_ex]() -> void { throw _ex; }; });
30 /**
31 * Exception storage
33 class storage
35 public:
36 /**
37 * Null object.
39 storage();
40 /**
41 * Store an exception.
43 * Parameter e: The exception.
45 storage(std::exception& e);
46 /**
47 * Rethrow the exception.
49 void rethrow();
50 /**
51 * Is anything here?
53 operator bool();
54 private:
55 bool null;
56 bool oom;
57 std::function<void()> do_rethrow;
61 #endif