Index: base/mac/scoped_nsexception_enabler.mm |
diff --git a/base/mac/scoped_nsexception_enabler.mm b/base/mac/scoped_nsexception_enabler.mm |
index f5559f0455a26730b6f29b372345809ee258c5f0..52bddb2bb6e25143682acb35f3882db80a37eae7 100644 |
--- a/base/mac/scoped_nsexception_enabler.mm |
+++ b/base/mac/scoped_nsexception_enabler.mm |
@@ -12,6 +12,15 @@ using base::LazyInstance; |
using base::LeakyLazyInstanceTraits; |
using base::ThreadLocalBoolean; |
+// When C++ exceptions are disabled, the C++ library defines |try| and |
+// |catch| so as to allow exception-expecting C++ code to build properly when |
+// language support for exceptions is not present. These macros interfere |
+// with the use of |@try| and |@catch| in Objective-C files such as this one. |
+// Undefine these macros here, after everything has been #included, since |
+// there will be no C++ uses and only Objective-C uses from this point on. |
+#undef try |
+#undef catch |
+ |
namespace { |
// Whether to allow NSExceptions to be raised on the current thread. |
@@ -31,6 +40,17 @@ void SetNSExceptionsAllowed(bool allowed) { |
return g_exceptionsAllowed.Get().Set(allowed); |
} |
+id PerformSelectorIgnoringExceptions(NSObject* target, SEL sel) { |
+ id ret = nil; |
+ @try { |
+ base::mac::ScopedNSExceptionEnabler enable; |
+ ret = [target performSelector:sel]; |
+ } |
+ @catch(id exception) { |
+ } |
+ return ret; |
+} |
+ |
ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() { |
was_enabled_ = GetNSExceptionsAllowed(); |
SetNSExceptionsAllowed(true); |