I have a class I want to redirect user to Error page if theres been an: uncaught exception , a caught exception or a custom exception. I also want to flick off an error email. (so that I’m notified).
I can’t access the current View Controller within this class (in the case of an uncaught exception). Because its triggered with the delegate listener onUncaughtException(NSException* exception).
How can I access the current view controller, or failing that, modally redirect user to an Error view controller?
#import "ErrorHelper.h"
#import "ErrorViewController.h"
#import "Global.h"
#import "AppDelegate.h"
@implementation ErrorHelper
+(void) handleUncaughtError:(NSException*) exception
{
NSLog(@"Uncaught exception occurred!");
[self sendErrorEmailIfAppropriate:exception :nil];
[self redirectToErrorPage];
}
+(void) handleCaughtError:(NSException*) exception
{
NSLog(@"Error caught!!");
[self sendErrorEmailIfAppropriate:exception :nil];
[self redirectToErrorPage];
}
+(void) handleCaughtCustomError:(NSString*) ref :(NSString*) details
{
NSLog(@"Custom error caught!!");
//can do conditional branching on @ref, to do appropriate action.
[self sendErrorEmailIfAppropriate:nil :details];
[self redirectToErrorPage];
}
+(void) sendErrorEmailIfAppropriate:(NSException*) exception :(NSString*)details
{
if([[Global get] isInTestMode] || [[Global get] isInLiveMode]) {
bool isCustomException = details != nil;
}
}
+(void) redirectToErrorPage
{
/*Try redirect user to error page
E.G:
-There's been an error, our App Dev team will try and resolve the issue for you
-Regards -Dev team
*/
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
}
@end
I tried this from: exception_handler Its working! Just write your email sending code instead of the alert view.
In interface,