diff options
Diffstat (limited to 'base/mac')
-rw-r--r-- | base/mac/scoped_nsexception_enabler.h | 7 | ||||
-rw-r--r-- | base/mac/scoped_nsexception_enabler.mm | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/base/mac/scoped_nsexception_enabler.h b/base/mac/scoped_nsexception_enabler.h index e1d0b3c..e28e516 100644 --- a/base/mac/scoped_nsexception_enabler.h +++ b/base/mac/scoped_nsexception_enabler.h @@ -45,8 +45,15 @@ BASE_EXPORT void SetNSExceptionsAllowed(bool allowed); // Executes [target performSelector:sel] with fatal-exceptions turned // off, and returns the result. If an exception is thrown during the // perform, nil is returned. +// TODO(shess): Deprecated, convert to RunBlockIgnoringExceptions(). BASE_EXPORT id PerformSelectorIgnoringExceptions(NSObject* target, SEL sel); +// Executes |block| with fatal-exceptions turned off, and returns the +// result. If an exception is thrown during the perform, nil is +// returned. +typedef id (^BlockReturningId)(); +BASE_EXPORT id RunBlockIgnoringExceptions(BlockReturningId block); + } // namespace mac } // namespace base diff --git a/base/mac/scoped_nsexception_enabler.mm b/base/mac/scoped_nsexception_enabler.mm index 9898789..44d4e19 100644 --- a/base/mac/scoped_nsexception_enabler.mm +++ b/base/mac/scoped_nsexception_enabler.mm @@ -50,6 +50,17 @@ id PerformSelectorIgnoringExceptions(NSObject* target, SEL sel) { return ret; } +id RunBlockIgnoringExceptions(BlockReturningId block) { + id ret = nil; + @try { + base::mac::ScopedNSExceptionEnabler enable; + ret = block(); + } + @catch(id exception) { + } + return ret; +} + ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() { was_enabled_ = GetNSExceptionsAllowed(); SetNSExceptionsAllowed(true); |