[a1aecb1] | 1 | /*
|
---|
[b57a3ee] | 2 | * Copyright (c) 2018 Jaroslav Jindrak
|
---|
[a1aecb1] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
[9396c52] | 28 |
|
---|
| 29 | #include <cstdlib>
|
---|
[a1aecb1] | 30 | #include <exception>
|
---|
| 31 |
|
---|
| 32 | namespace std
|
---|
| 33 | {
|
---|
[1610aa35] | 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 |
|
---|
[9396c52] | 63 | [[noreturn]] void terminate() noexcept
|
---|
| 64 | {
|
---|
[1610aa35] | 65 | if (aux::term_handler)
|
---|
| 66 | aux::term_handler();
|
---|
| 67 |
|
---|
[9396c52] | 68 | abort();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[1610aa35] | 71 | bool uncaught_exception() noexcept
|
---|
[a1aecb1] | 72 | {
|
---|
[1610aa35] | 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_;
|
---|
[a1aecb1] | 125 | }
|
---|
| 126 | }
|
---|