Reputation: 1927
I read somewhere not to exception handle when developing in Android, is that true?
If one does need to exception handle are there any logging tools for 2.1 and above?
If shouldn't exception handle, why is it not recommended to at least use the below? try { body-code } catch (exception-classname variable-name) { handler-code }
Upvotes: 4
Views: 1177
Reputation: 2140
The universal rule for handling exceptions should be to never attempt to catch any exception that you are not in a position to do anything about.
Upvotes: 1
Reputation: 688
Exceptions on android are working fine and is preferred. It is used in the android classes so you have to use it sometimes. Exceptions add a bit overhead in the VM and many devices have limited cpu and battery.
Don't be afraid to use exceptions to write readable code, but don't use them excessively just because you can.
Upvotes: 0
Reputation: 52247
I never heard that you shouldn't handle exceptions in Android and I can't think of a signle argument for this statement.
Whenever you can handle an exception i would use the try/catch block to handle the exception right at the place. When it is not possible to handle the exception there, I would throw the exception, and handle it somewhere higher in the method-calling-hierarchy.
Then, there is also a UncaughtExceptionHandler. You can define this ExceptionHandler in your activity. This exception handler will catch all exceptions that are thrown and that aren't handled any where else.
However, I would not recommend to just "silenty" catch them there.
Upvotes: 2
Reputation: 9902
This is not true, there are always scenarios where you need try catch exception handling code. There are built in logging classes that you can post messages with severity levels to and view while debugging or do something more useful for deployed apps like sending them somewhere.
Upvotes: 6