Bug 1910362 - Create new Nimbus helper r=aaronmt,ohorvath
[gecko.git] / xpcom / base / nsObjCExceptions.h
blobe8c2059d8e5927c19e0cea8efb5c5b36e6d82cd1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsObjCExceptions_h_
8 #define nsObjCExceptions_h_
10 // Undo the damage that exception_defines.h does.
11 #undef try
12 #undef catch
14 @class NSException;
16 // See Mozilla bug 163260.
17 // This file can only be included in an Objective-C context.
19 void nsObjCExceptionLog(NSException* aException);
21 namespace mozilla {
23 // Check if this is an exception that's outside of our control.
24 // Called when an exception bubbles up to the native event loop.
25 bool ShouldIgnoreObjCException(NSException* aException);
27 } // namespace mozilla
29 // For wrapping blocks of Obj-C calls which are not expected to throw exception.
30 // Causes a MOZ_CRASH if an Obj-C exception is encountered.
31 #define NS_OBJC_BEGIN_TRY_ABORT_BLOCK @try {
32 #define NS_OBJC_END_TRY_ABORT_BLOCK \
33 } \
34 @catch (NSException * _exn) { \
35 nsObjCExceptionLog(_exn); \
36 MOZ_CRASH("Encountered unexpected Objective C exception"); \
39 // For wrapping blocks of Obj-C calls. Logs the exception and moves on.
40 #define NS_OBJC_BEGIN_TRY_IGNORE_BLOCK @try {
41 #define NS_OBJC_END_TRY_IGNORE_BLOCK \
42 } \
43 @catch (NSException * _exn) { \
44 nsObjCExceptionLog(_exn); \
47 // Same as above IGNORE_BLOCK but returns a value after the try/catch block.
48 #define NS_OBJC_BEGIN_TRY_BLOCK_RETURN @try {
49 #define NS_OBJC_END_TRY_BLOCK_RETURN(_rv) \
50 } \
51 @catch (NSException * _exn) { \
52 nsObjCExceptionLog(_exn); \
53 } \
54 return _rv;
56 #endif // nsObjCExceptions_h_