1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is dual licensed under the MIT and the University of Illinois Open 7// Source Licenses. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_ABI_MICROSOFT 12#error this header can only be used when targeting the MSVC ABI 13#endif 14 15#include <stdio.h> 16#include <stdlib.h> 17#include <eh.h> 18#include <corecrt_terminate.h> 19 20namespace std { 21 22// libcxxrt provides implementations of these functions itself. 23unexpected_handler 24set_unexpected(unexpected_handler func) _NOEXCEPT { 25 return ::set_unexpected(func); 26} 27 28unexpected_handler get_unexpected() _NOEXCEPT { 29 return ::_get_unexpected(); 30} 31 32_LIBCPP_NORETURN 33void unexpected() { 34 (*get_unexpected())(); 35 // unexpected handler should not return 36 terminate(); 37} 38 39terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { 40 return ::set_terminate(func); 41} 42 43terminate_handler get_terminate() _NOEXCEPT { 44 return ::_get_terminate(); 45} 46 47_LIBCPP_NORETURN 48void terminate() _NOEXCEPT 49{ 50#ifndef _LIBCPP_NO_EXCEPTIONS 51 try 52 { 53#endif // _LIBCPP_NO_EXCEPTIONS 54 (*get_terminate())(); 55 // handler should not return 56 fprintf(stderr, "terminate_handler unexpectedly returned\n"); 57 ::abort(); 58#ifndef _LIBCPP_NO_EXCEPTIONS 59 } 60 catch (...) 61 { 62 // handler should not throw exception 63 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); 64 ::abort(); 65 } 66#endif // _LIBCPP_NO_EXCEPTIONS 67} 68 69bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } 70 71int uncaught_exceptions() _NOEXCEPT { 72 return __uncaught_exceptions(); 73} 74 75bad_array_length::bad_array_length() _NOEXCEPT 76{ 77} 78 79bad_array_length::~bad_array_length() _NOEXCEPT 80{ 81} 82 83const char* 84bad_array_length::what() const _NOEXCEPT 85{ 86 return "bad_array_length"; 87} 88 89} // namespace std 90