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