| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include <cstdlib>
|
|---|
| 8 | #include <exception>
|
|---|
| 9 |
|
|---|
| 10 | namespace std
|
|---|
| 11 | {
|
|---|
| 12 | const char* exception::what() const noexcept
|
|---|
| 13 | {
|
|---|
| 14 | return "std::exception";
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | const char* bad_exception::what() const noexcept
|
|---|
| 18 | {
|
|---|
| 19 | return "std::bad_exception";
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | namespace aux
|
|---|
| 23 | {
|
|---|
| 24 | terminate_handler term_handler{nullptr};
|
|---|
| 25 | unexpected_handler unex_handler{nullptr};
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | terminate_handler get_terminate() noexcept
|
|---|
| 29 | {
|
|---|
| 30 | return aux::term_handler;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | terminate_handler set_terminate(terminate_handler h) noexcept
|
|---|
| 34 | {
|
|---|
| 35 | auto res = aux::term_handler;
|
|---|
| 36 | aux::term_handler = h;
|
|---|
| 37 |
|
|---|
| 38 | return res;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | [[noreturn]] void terminate() noexcept
|
|---|
| 42 | {
|
|---|
| 43 | if (aux::term_handler)
|
|---|
| 44 | aux::term_handler();
|
|---|
| 45 |
|
|---|
| 46 | abort();
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | bool uncaught_exception() noexcept
|
|---|
| 50 | {
|
|---|
| 51 | /**
|
|---|
| 52 | * Note: The implementation of these two
|
|---|
| 53 | * functions currently uses our mock
|
|---|
| 54 | * exception handling system.
|
|---|
| 55 | */
|
|---|
| 56 | return aux::exception_thrown;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | int uncaught_exceptins() noexcept
|
|---|
| 60 | {
|
|---|
| 61 | return aux::exception_thrown ? 1 : 0;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | unexpected_handler get_unexpected() noexcept
|
|---|
| 65 | {
|
|---|
| 66 | return aux::unex_handler;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | unexpected_handler set_unexpected(unexpected_handler h) noexcept
|
|---|
| 70 | {
|
|---|
| 71 | auto res = aux::unex_handler;
|
|---|
| 72 | aux::unex_handler = h;
|
|---|
| 73 |
|
|---|
| 74 | return res;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | [[noreturn]] void unexpected()
|
|---|
| 78 | {
|
|---|
| 79 | if (aux::unex_handler)
|
|---|
| 80 | aux::unex_handler();
|
|---|
| 81 |
|
|---|
| 82 | terminate();
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | exception_ptr current_exception() noexcept
|
|---|
| 86 | {
|
|---|
| 87 | return exception_ptr{};
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | [[noreturn]] void rethrow_exception(exception_ptr)
|
|---|
| 91 | {
|
|---|
| 92 | terminate();
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | [[noreturn]] void nested_exception::throw_nested() const
|
|---|
| 96 | {
|
|---|
| 97 | terminate();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | exception_ptr nested_exception::nested_ptr() const noexcept
|
|---|
| 101 | {
|
|---|
| 102 | return ptr_;
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|