Skip to content

Commit

Permalink
add ignoresExceptions property.
Browse files Browse the repository at this point in the history
  • Loading branch information
croath committed Jan 22, 2014
1 parent 8b3b931 commit 10e13ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ If you wish to do custom allocation of a controller, you can use `+allocWithRout
}
```
Set `ignoresExceptions` to `YES` to NOT throw exceptions (suggested for a Release/Distribution version)
```objective-c
[[Routable sharedRouter] setIgnoresExceptions:YES];
```

## Installation

### [CocoaPods](http://cocoapods.org/)
Expand Down
5 changes: 5 additions & 0 deletions Routable/Routable.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ typedef void (^RouterOpenCallback)(NSDictionary *params);
/// @name Mapping URLs
///-------------------------------

/**
The property controls for throwing exception or not in your app. NOT throwing any exceptions if set to `YES`, default `NO`;
*/
@property (readwrite, nonatomic, assign) BOOL ignoresExceptions;

/**
Map a URL format to an anonymous callback
@param format A URL format (i.e. "users/:id" or "logout")
Expand Down
12 changes: 12 additions & 0 deletions Routable/Routable.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ - (void)open:(NSString *)url animated:(BOOL)animated {
}

if (!self.navigationController) {
if (_ignoresExceptions) {
return;
}

@throw [NSException exceptionWithName:@"NavigationControllerNotProvided"
reason:@"Router#navigationController has not been set to a UINavigationController instance"
userInfo:nil];
Expand Down Expand Up @@ -272,6 +276,10 @@ - (RouterParams *)routerParamsForUrl:(NSString *)url {
}

if (!openParams) {
if (_ignoresExceptions) {
return nil;
}

@throw [NSException exceptionWithName:@"RouteNotFoundException"
reason:[NSString stringWithFormat:ROUTE_NOT_FOUND_FORMAT, url]
userInfo:nil];
Expand Down Expand Up @@ -326,6 +334,10 @@ - (UIViewController *)controllerForRouterParams:(RouterParams *)params {
#pragma clang diagnostic pop

if (controller == nil) {
if (_ignoresExceptions) {
return nil;
}

@throw [NSException exceptionWithName:@"RoutableInitializerNotFound"
reason:[NSString stringWithFormat:INVALID_CONTROLLER_FORMAT, NSStringFromClass(controllerClass), NSStringFromSelector(CONTROLLER_CLASS_SELECTOR), NSStringFromSelector(CONTROLLER_SELECTOR)]
userInfo:nil];
Expand Down

0 comments on commit 10e13ce

Please sign in to comment.