Roll src/third_party/WebKit 129741d:3ffd812 (svn 192915:192926)
[chromium-blink-merge.git] / base / mac / scoped_nsexception_enabler.h
blob484dd53449666adb06095b7a4741d37afd5b7ebe
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_
6 #define BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_
8 #import <Foundation/Foundation.h>
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
13 namespace base {
14 namespace mac {
16 // BrowserCrApplication attempts to restrict throwing of NSExceptions
17 // because they interact badly with C++ scoping rules. Unfortunately,
18 // there are some cases where exceptions must be supported, such as
19 // when third-party printer drivers are used. These helpers can be
20 // used to enable exceptions for narrow windows.
22 // Make it easy to safely allow NSException to be thrown in a limited
23 // scope. Note that if an exception is thrown, then this object will
24 // not be appropriately destructed! If the exception ends up in the
25 // top-level event loop, things are cleared in -reportException:. If
26 // the exception is caught at a lower level, a higher level scoper
27 // should eventually reset things.
28 class BASE_EXPORT ScopedNSExceptionEnabler {
29 public:
30 ScopedNSExceptionEnabler();
31 ~ScopedNSExceptionEnabler();
33 private:
34 bool was_enabled_;
36 DISALLOW_COPY_AND_ASSIGN(ScopedNSExceptionEnabler);
39 // Access the exception setting for the current thread. This is for
40 // the support code in BrowserCrApplication, other code should use
41 // the scoper.
42 BASE_EXPORT bool GetNSExceptionsAllowed();
43 BASE_EXPORT void SetNSExceptionsAllowed(bool allowed);
45 // Executes |block| with fatal-exceptions turned off, and returns the
46 // result. If an exception is thrown during the perform, nil is
47 // returned.
48 typedef id (^BlockReturningId)();
49 BASE_EXPORT id RunBlockIgnoringExceptions(BlockReturningId block);
51 } // namespace mac
52 } // namespace base
54 #endif // BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_