msvc_raise_wrappers.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: sw=4 ts=4 et :
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include <stdio.h>
  8. #include "mozalloc_abort.h"
  9. __declspec(noreturn) static void abort_from_exception(const char* const which,
  10. const char* const what);
  11. static void
  12. abort_from_exception(const char* const which, const char* const what)
  13. {
  14. fprintf(stderr, "fatal: STL threw %s: ", which);
  15. mozalloc_abort(what);
  16. }
  17. namespace std {
  18. // NB: user code is not supposed to touch the std:: namespace. We're
  19. // doing this after careful review because we want to define our own
  20. // exception throwing semantics. Don't try this at home!
  21. MFBT_API __declspec(noreturn) void
  22. moz_Xinvalid_argument(const char* what)
  23. {
  24. abort_from_exception("invalid_argument", what);
  25. }
  26. MFBT_API __declspec(noreturn) void
  27. moz_Xlength_error(const char* what)
  28. {
  29. abort_from_exception("length_error", what);
  30. }
  31. MFBT_API __declspec(noreturn) void
  32. moz_Xout_of_range(const char* what)
  33. {
  34. abort_from_exception("out_of_range", what);
  35. }
  36. MFBT_API __declspec(noreturn) void
  37. moz_Xoverflow_error(const char* what)
  38. {
  39. abort_from_exception("overflow_error", what);
  40. }
  41. MFBT_API __declspec(noreturn) void
  42. moz_Xruntime_error(const char* what)
  43. {
  44. abort_from_exception("runtime_error", what);
  45. }
  46. MFBT_API __declspec(noreturn) void
  47. moz_Xbad_function_call()
  48. {
  49. abort_from_exception("bad_function_call", "bad function call");
  50. }
  51. } // namespace std