Is there anyway in ios to handle all the exceptions that occurred in entire application in a single try catch block.
If yes where should I write this block.
Is there anyway in ios to handle all the exceptions that occurred in entire application in a single try catch block.
If yes where should I write this block.
Assuming the question is about Objective-C there is no need to handle exceptions because they are not to be used for program control. Exceptions are only to be used to catch non-recoverable programming errors so if you get one the code needs to be fixed.
In general exceptions across stack frames are not handled in a manner that is recoverable.
The best thing to do is add an exception breakpoint in Xcode so you can better examine exceptions:
From the Mian Menu Debug:Breakpoints:Create Exception Breakpoint. Run the app to get the breakpoint. When you hit the exception breakpoint click debug continue a couple of times and you will get a backtrace and more error info. Add that and an exact copy of Xcode/Debugger messages to the question.
It is also a good idea to change this breakpoint to "Objective-C only."
You might want to have a look into the concept of handling exceptions globally in iOS. I might not be able to give the most correct answer but these links can spread some more light on what you might just want.
Global Exception Handler in iOS
Hope this helps.
You can use NSSetUncaughtExceptionHandler
to set the handler.
Swift:
NSSetUncaughtExceptionHandler { (exception) in
while true {
sleep(UInt32(0.5))
}
}
Objective-C:
void handleException(NSException* exception) {
while true {
sleep(0.5);
}
}
NSSetUncaughtExceptionHandler(handleException);
When the handler is returned, the app crashes and Xcode shows the error. So you can run a loop until you want to quit the app. I do not recommend to keep the app running normally, but you can show for example an alert saying an error occurred and when the user taps a button, the app crashes. Use a flag for the loop.