diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /xpcom/base/nsObjCExceptions.h | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/base/nsObjCExceptions.h')
-rw-r--r-- | xpcom/base/nsObjCExceptions.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/xpcom/base/nsObjCExceptions.h b/xpcom/base/nsObjCExceptions.h new file mode 100644 index 0000000000..80b9f4a61c --- /dev/null +++ b/xpcom/base/nsObjCExceptions.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef nsObjCExceptions_h_ +#define nsObjCExceptions_h_ + +// Undo the damage that exception_defines.h does. +#undef try +#undef catch + +@class NSException; + +// See Mozilla bug 163260. +// This file can only be included in an Objective-C context. + +void nsObjCExceptionLog(NSException* aException); + +namespace mozilla { + +// Check if this is an exception that's outside of our control. +// Called when an exception bubbles up to the native event loop. +bool ShouldIgnoreObjCException(NSException* aException); + +} + +// For wrapping blocks of Obj-C calls which are not expected to throw exception. +// Causes a MOZ_CRASH if an Obj-C exception is encountered. +#define NS_OBJC_BEGIN_TRY_ABORT_BLOCK @try { +#define NS_OBJC_END_TRY_ABORT_BLOCK \ + } \ + @catch (NSException * _exn) { \ + nsObjCExceptionLog(_exn); \ + MOZ_CRASH("Encountered unexpected Objective C exception"); \ + } + +// For wrapping blocks of Obj-C calls. Logs the exception and moves on. +#define NS_OBJC_BEGIN_TRY_IGNORE_BLOCK @try { +#define NS_OBJC_END_TRY_IGNORE_BLOCK \ + } \ + @catch (NSException * _exn) { \ + nsObjCExceptionLog(_exn); \ + } + +// Same as above IGNORE_BLOCK but returns a value after the try/catch block. +#define NS_OBJC_BEGIN_TRY_BLOCK_RETURN @try { +#define NS_OBJC_END_TRY_BLOCK_RETURN(_rv) \ + } \ + @catch (NSException * _exn) { \ + nsObjCExceptionLog(_exn); \ + } \ + return _rv; + +#endif // nsObjCExceptions_h_ |