Changeset 1610aa35 in mainline
- Timestamp:
- 2018-07-05T21:41:23Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 17c41c3
- Parents:
- 68cfab1
- git-author:
- Dzejrou <dzejrou@…> (2018-05-08 16:23:51)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
- Location:
- uspace/lib/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/exception.hpp
r68cfab1 r1610aa35 30 30 #define LIBCPP_EXCEPTION 31 31 32 #include <internal/trycatch.hpp> 33 32 34 namespace std 33 35 { 34 [[noreturn]] void terminate() noexcept; 36 /** 37 * 18.8.1, class exception: 38 */ 35 39 36 40 class exception 37 41 { 38 42 public: 39 exception() = default; 40 exception(const exception&) = default; 41 exception& operator=(const exception&) noexcept; 42 virtual const char* what() const; 43 exception() noexcept = default; 44 exception(const exception&) noexcept = default; 45 exception& operator=(const exception&) noexcept = default; 43 46 virtual ~exception() = default; 47 virtual const char* what() const noexcept; 44 48 }; 49 50 /** 51 * 18.8.2, class bad_exception: 52 */ 53 54 class bad_exception: public exception 55 { 56 public: 57 bad_exception() noexcept = default; 58 bad_exception(const bad_exception&) noexcept = default; 59 bad_exception& operator=(const bad_exception&) noexcept = default; 60 61 virtual const char* what() const noexcept; 62 }; 63 64 /** 65 * 18.8.3, abnormal termination: 66 */ 67 68 using terminate_handler = void (*)(); 69 70 terminate_handler get_terminate() noexcept; 71 terminate_handler set_terminate(terminate_handler) noexcept; 72 [[noreturn]] void terminate() noexcept; 73 74 /** 75 * 18.8.4, uncaght_exceptions: 76 */ 77 78 bool uncaught_exception() noexcept; 79 int uncaught_exceptions() noexcept; 80 81 using unexpected_handler = void (*)(); 82 83 unexpected_handler get_unexpected() noexcept; 84 unexpected_handler set_unexpected(unexpected_handler) noexcept; 85 [[noreturn]] void unexpected(); 86 87 /** 88 * 18.8.5, exception propagation: 89 */ 90 91 namespace aux 92 { 93 class exception_ptr_t 94 { /* DUMMY BODY */ }; 95 } 96 97 using exception_ptr = aux::exception_ptr_t; 98 99 exception_ptr current_exception() noexcept; 100 [[noreturn]] void rethrow_exception(exception_ptr); 101 102 template<class E> 103 exception_ptr make_exception_ptr(E e) noexcept 104 { 105 return exception_ptr{}; 106 } 107 108 class nested_exception 109 { 110 public: 111 nested_exception() noexcept = default; 112 nested_exception(const nested_exception&) noexcept = default; 113 nested_exception& operator=(const nested_exception&) noexcept = default; 114 virtual ~nested_exception() = default; 115 116 [[noreturn]] void throw_nested() const; 117 exception_ptr nested_ptr() const noexcept; 118 119 private: 120 exception_ptr ptr_; 121 }; 122 123 template<class E> 124 [[noreturn]] void throw_with_nested(E&& e) 125 { 126 terminate(); 127 } 128 129 template<class E> 130 void rethrow_if_nested(const E& e) 131 { 132 auto casted = dynamic_cast<const nested_exception*>(&e); 133 if (casted) 134 casted->throw_nested(); 135 } 45 136 } 46 137 -
uspace/lib/cpp/src/exception.cpp
r68cfab1 r1610aa35 32 32 namespace std 33 33 { 34 const char* exception::what() const noexcept 35 { 36 return "std::exception"; 37 } 38 39 const char* bad_exception::what() const noexcept 40 { 41 return "std::bad_exception"; 42 } 43 44 namespace aux 45 { 46 terminate_handler term_handler{nullptr}; 47 unexpected_handler unex_handler{nullptr}; 48 } 49 50 terminate_handler get_terminate() noexcept 51 { 52 return aux::term_handler; 53 } 54 55 terminate_handler set_terminate(terminate_handler h) noexcept 56 { 57 auto res = aux::term_handler; 58 aux::term_handler = h; 59 60 return res; 61 } 62 34 63 [[noreturn]] void terminate() noexcept 35 64 { 65 if (aux::term_handler) 66 aux::term_handler(); 67 36 68 abort(); 37 69 } 38 70 39 const char* exception::what() const71 bool uncaught_exception() noexcept 40 72 { 41 return "std::exception"; 73 /** 74 * Note: The implementation of these two 75 * functions currently uses our mock 76 * exception handling system. 77 */ 78 return aux::exception_thrown; 79 } 80 81 int uncaught_exceptins() noexcept 82 { 83 return aux::exception_thrown ? 1 : 0; 84 } 85 86 unexpected_handler get_unexpected() noexcept 87 { 88 return aux::unex_handler; 89 } 90 91 unexpected_handler set_unexpected(unexpected_handler h) noexcept 92 { 93 auto res = aux::unex_handler; 94 aux::unex_handler = h; 95 96 return res; 97 } 98 99 [[noreturn]] void unexpected() 100 { 101 if (aux::unex_handler) 102 aux::unex_handler(); 103 104 terminate(); 105 } 106 107 exception_ptr current_exception() noexcept 108 { 109 return exception_ptr{}; 110 } 111 112 [[noreturn]] void rethrow_exception(exception_ptr) 113 { 114 terminate(); 115 } 116 117 [[noreturn]] void nested_exception::throw_nested() const 118 { 119 terminate(); 120 } 121 122 exception_ptr nested_exception::nested_ptr() const noexcept 123 { 124 return ptr_; 42 125 } 43 126 }
Note:
See TracChangeset
for help on using the changeset viewer.