OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ | |
6 #define BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ | |
7 | |
8 #import <Foundation/Foundation.h> | |
9 | |
10 #include "base/base_export.h" | |
11 #include "base/basictypes.h" | |
12 | |
13 namespace base { | |
14 namespace mac { | |
15 | |
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. | |
21 | |
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(); | |
32 | |
33 private: | |
34 bool was_enabled_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(ScopedNSExceptionEnabler); | |
37 }; | |
38 | |
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); | |
44 | |
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); | |
50 | |
51 } // namespace mac | |
52 } // namespace base | |
53 | |
54 #endif // BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ | |
OLD | NEW |