michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: sw=4 ts=4 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_throw_gcc_h michael@0: #define mozilla_throw_gcc_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include // snprintf michael@0: #include // strerror michael@0: michael@0: // For gcc, we define these inline to abort so that we're absolutely michael@0: // certain that (i) no exceptions are thrown from Gecko; (ii) these michael@0: // errors are always terminal and caught by breakpad. michael@0: michael@0: #include "mozilla/mozalloc_abort.h" michael@0: michael@0: namespace std { michael@0: michael@0: // NB: user code is not supposed to touch the std:: namespace. We're michael@0: // doing this after careful review because we want to define our own michael@0: // exception throwing semantics. Don't try this at home! michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_bad_exception(void) michael@0: { michael@0: mozalloc_abort("fatal: STL threw bad_exception"); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_bad_alloc(void) michael@0: { michael@0: mozalloc_abort("fatal: STL threw bad_alloc"); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_bad_cast(void) michael@0: { michael@0: mozalloc_abort("fatal: STL threw bad_cast"); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_bad_typeid(void) michael@0: { michael@0: mozalloc_abort("fatal: STL threw bad_typeid"); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_logic_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_domain_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_invalid_argument(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_length_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_out_of_range(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_runtime_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_range_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_overflow_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_underflow_error(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_ios_failure(const char* msg) michael@0: { michael@0: mozalloc_abort(msg); michael@0: } michael@0: michael@0: MOZ_NORETURN MOZ_ALWAYS_INLINE void michael@0: __throw_system_error(int err) michael@0: { michael@0: char error[128]; michael@0: snprintf(error, sizeof(error)-1, michael@0: "fatal: STL threw system_error: %s (%d)", strerror(err), err); michael@0: mozalloc_abort(error); michael@0: } michael@0: michael@0: } // namespace std michael@0: michael@0: #endif // mozilla_throw_gcc_h