Permalink
Browse files

Wrapping callFunctionNamed with a try/catch.

  • Loading branch information...
ccgus committed Aug 17, 2012
1 parent 3736a4b commit c00dc512d643fd1144cded8580a4b70a1e779588
Showing with 16 additions and 7 deletions.
  1. +16 −7 src/JSTalk.m
View
@@ -301,17 +301,26 @@ - (BOOL)hasFunctionNamed:(NSString*)name {
- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
- [self pushAsCurrentJSTalk];
+ id returnValue = nil;
- id foo = [_mochaRuntime callFunctionWithName:name withArgumentsInArray:args];
+ @try {
+
+ [self pushAsCurrentJSTalk];
+
+ returnValue = [_mochaRuntime callFunctionWithName:name withArgumentsInArray:args];
+
+ if (returnValue == [MOUndefined undefined]) {
+ returnValue = nil;
+ }
+ }
+ @catch (NSException * e) {
+ NSLog(@"Exception: %@", e);
+ [self print:[e description]];
+ }
[self popAsCurrentJSTalk];
- if (foo == [MOUndefined undefined]) {
- return nil;
- }
-
- return foo;
+ return returnValue;
}

0 comments on commit c00dc51

Please sign in to comment.