Catching Exceptions in iOS application - ios

I am developing an application and I have to submit an error report, I have to save all errors I face in database or word file, etc. Exceptions have to be saved in order to know what kind of exceptions we are facing and to fix them later on.
I have to write code in one place to catch any error that happens. Can anybody help me in this? Where do I write this code and even what is the code to be written in order to achieve my aim?

Here are a couple of links that discuss catching exceptions:
Xcode all exceptions breakpoint.
Installing exception handler
Hope that helps!

Related

Does FirebaseApp.configure() actually raise exceptions?

The documentation implies it will raise an exception if any part of the configuration fails but it doesn't seem possible to actually catch an exception (Swift 4.) Certainly, one cannot wrap the statement in a do..catch block. If it fails, is my app doomed to just crash or continue and try (and fail) to operate without Firebase?
FirebaseApp.configure() will only crash if there's something wrong with the configuration file that you download from Firebase's console.
If it worked for you one time, there won't be a reason for it to crash later unless you change the configuration file. So no need to try to catch the error or any special effort.

How to handle all the exceptions in ios app

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.
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.
iOS Global Exception Handling
Global Exception Handler in iOS
Hope this helps.
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 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.

"<Program> has stopped working" explanation

Can someone explain me when Windows shows this message?
What do i have to do to stop my Program from throwing this exception?
I have a Delphi Windows Forms Program which throws this message short after doing some SQL operations.
So i do the SQL, everything seems fine at first, but at a random time after that windows is killing it by showing this message...
the intresting thing is, it only occours while debugging.
When i'm not debugging it's running perfectly stable.
EDIT: Using RAD-Studio2009
I dont want to turn off the message completely(Only hint i found by using Google)
i want to stop my program giving windows a Reason to do that.
Windows shows this message when an unhandled exception leaks out of your application. This is a fatal condition. Something very wrong has happened with your application because exceptions should all be caught.
You need to work out what is throwing the exception and why it is not being caught. The very first step is to expand the details of the error dialog and find out which module the fault is occurring in, what the fault is and so on. That should yield some high level clues at the very least.
Most likely the Delphi debugger will not be able to help you for such a fault. You need to configure your system to arrange for a crash dump to be produced by the Windows Error Reporting service. Then you can load up the error report in a tool like WinDbg and try to figure it out.

How to disable all exception raising in Delphi?

Is there a way to disable all the dialog boxes when an exception or error occurs(like access violations, indy socket errors, timeouts etc.)? They are thrown sometimes in my program, but these errors aren't fatal in any way and can be ignored, just the dialog boxes are disturbing. I use Delphi 7.
If you just don't wont to show the exception window then go to:
Tools/Options/Debugger Options/Language Exceptions and disable CheckBox Notify on language exceptions. That is walid for Delphi 2010.
(I don't remember if it is the same CheckBox in Delphi 7).
EDIT:
In some cases the exceptions are unavoidable, specially when we are working with unknown files from internet. So, I believe that your exceptions are handled properly under Indy, just switch-off Notify on language exceptions
You can customize Application.OnException event. But IMVHO...
Application.OnException suits best to log exceptions which you forgot to handle.
Application.OnException should be used to catch exceptions only when you desperately need performance (in this case you should anticipate broken execution paths).
And:
Access violations are fatal errors - you have to trace and get rid of all AV's.
You can't hide exception dialogs just by Application.OnException override - you should use try finally/except in right way.
Bypass the Application.OnException event. However I would NOT recommend hiding every exception, IMHO that is poor design.
# GJ - Delphi 2007 has that check box. But again as was mentioned above, access violation ain't the kind of exceptions that one should ignore.

How to make xCode stop logging error within a #try #catch

All,
I have a chunk of code that runs over a lot of records and in about half of the cases fails (this is ok, some records simply don't have the required data) I put this code in a #try #catch block to make it run smoothly, we try to do our thing, if we fail, we have some default action.
When it fails in the #try block often it is a unrecognized selector error, since it is in the #try block I catch this error, but it still gets logged everytime, even when I don't log from my #catch block. This is very annoying because it clogs up my logging. If I want errors from a #try/#catch logged, I will take care of that in the #catch right?
How can I stop XCode from logging errors in the #try block that are subsequently resolved in the #catch block?
I am using XCode 4.2
Thanks
In Objective-C using exceptions for any normal situation that can appear in a program is a no go. Exceptions are used only for discovering and catching programming errors and terminating gracefully. The problem is that all of the standard libraries (Cocoa, CoreFoundation, C standard library, ...) just are not build to handle exceptions and would fail to clean up resources if exceptions went through them.
Theoretically you could use exceptions if you made sure that you do your memory and other cleanup correctly and do not throw through foreign code. If you use ARC, there's a compiler switch -fobjc-arc-exceptions that would help you to get memory management (in your code) right.
Common practice is not to use exceptions at all (other than bugs, for example using NSAssert).
Exceptions themselves do not log any message to the console. Neither does Xcode (by default) log any exception throwing.
It's the error catching code that writes the messages before throwing exceptions. NSObject's doesNotRecognizeSelector: prints a message when unrecognized selectors are being sent. You cannot turn this off.
So you want to see certain log message but not others. How about redirecting the debugger output into a file. On that file use grep or a text editor with nice filtering to scan through message you want to see. Copy & paste from the gdb console into an edtor would do the same trick.

Resources