Does FirebaseApp.configure() actually raise exceptions? - ios

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.

Related

Can I fail a scenario from BeforeScenario and AfterScenario hooks?

Current dealing with an issue with exceptions being raised in hooks. When exceptions are thrown (at least from the "After" hooks), the previous scenario context is not disposed, which causes the log file for future scenarios to become unreadable.
As a temporary fix, I have added a try/catch around the test setup/teardown, however I want to be able to see that something has thrown without browsing the logs. We view the results from Jenkins, so if we could "fail" the test, we would be more likely to spot the issue.
Is there any way of doing this manually, without allowing the exception to be thrown?
In your catch block, do an intentional false assertion like something below..
Assert.True(false); //(Xunit)
Assert.IsTrue(false); //(Nunit)
This would make your test fail in the hooks without throwing the exception.

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.

Catching Exceptions in iOS application

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!

ActionScript Get crash call stack on iOS

I am using Adobe Air3.4 to develop an app on iOS. However, I met a crash only on release version and this crash doesn't happen on debug version. But I cannot get any crash info such as callstack from iOS. Do you have any method to deal with this kind of problem?
You can wrap the offending code in a try/catch statement. Inside the catch code block, you get an Error object that you can use to get the stack trace:
try
{
// some code that throws an exception
}
catch (e:Error)
{
trace(e.getStackTrace())
}
If you don't know which code is causing the error, and thus where to add the try/catch statement, you might have some luck with the UncaughtErrorEvent -- refer to the examples found at the bottom of the documentation for UncaughtErrorEvent that I linked to.
In fact, if you just want a stack trace in general, create a new Error object and use its getStackTrace() method anywhere in your code.
In addition to checking for errors as above, you should check the crash logs on your device to see if that provides any additional details.

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