Bug 513162 - Fix for intermittent failure in test_titlebar.xul, due to left over...
[mozilla-central.git] / memory / mozalloc / throw_gcc.h
blob1975c2e7c920ebbf1ef09c4076355bd92e7f4314
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 et :
3 */
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is Mozilla Code
19 * The Initial Developer of the Original Code is
20 * The Mozilla Foundation.
21 * Portions created by the Initial Developer are Copyright (C) 2010
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Chris Jones <jones.chris.g@gmail.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef mozilla_throw_gcc_h
42 #define mozilla_throw_gcc_h
44 #include <stdio.h> // snprintf
45 #include <string.h> // strerror
47 // For gcc, we define these inline to abort so that we're absolutely
48 // certain that (i) no exceptions are thrown from Gecko; (ii) these
49 // errors are always terminal and caught by breakpad.
51 #include "mozilla/mozalloc_abort.h"
53 namespace std {
55 // NB: user code is not supposed to touch the std:: namespace. We're
56 // doing this after careful review because we want to define our own
57 // exception throwing semantics. Don't try this at home!
59 inline void NS_NORETURN
60 __throw_bad_exception(void)
62 mozalloc_abort("fatal: STL threw bad_exception");
65 inline void NS_NORETURN
66 __throw_bad_alloc(void)
68 mozalloc_abort("fatal: STL threw bad_alloc");
71 inline void NS_NORETURN
72 __throw_bad_cast(void)
74 mozalloc_abort("fatal: STL threw bad_cast");
77 inline void NS_NORETURN
78 __throw_bad_typeid(void)
80 mozalloc_abort("fatal: STL threw bad_typeid");
83 inline void NS_NORETURN
84 __throw_logic_error(const char* msg)
86 mozalloc_abort(msg);
89 inline void NS_NORETURN
90 __throw_domain_error(const char* msg)
92 mozalloc_abort(msg);
95 inline void NS_NORETURN
96 __throw_invalid_argument(const char* msg)
98 mozalloc_abort(msg);
101 inline void NS_NORETURN
102 __throw_length_error(const char* msg)
104 mozalloc_abort(msg);
107 inline void NS_NORETURN
108 __throw_out_of_range(const char* msg)
110 mozalloc_abort(msg);
113 inline void NS_NORETURN
114 __throw_runtime_error(const char* msg)
116 mozalloc_abort(msg);
119 inline void NS_NORETURN
120 __throw_range_error(const char* msg)
122 mozalloc_abort(msg);
125 inline void NS_NORETURN
126 __throw_overflow_error(const char* msg)
128 mozalloc_abort(msg);
131 inline void NS_NORETURN
132 __throw_underflow_error(const char* msg)
134 mozalloc_abort(msg);
137 inline void NS_NORETURN
138 __throw_ios_failure(const char* msg)
140 mozalloc_abort(msg);
143 inline void NS_NORETURN
144 __throw_system_error(int err)
146 char error[128];
147 snprintf(error, sizeof(error)-1,
148 "fatal: STL threw system_error: %s (%d)", strerror(err), err);
149 mozalloc_abort(error);
152 } // namespace std
154 #endif // mozilla_throw_gcc_h