Explain about the exceptions of Android?

Asked 23-Jan-2018
Viewed 639 times

2 Answers


0

Exceptions in Android is similar to exception in java.
Throwable is the root class of all exceptions in java as shown in the image below. 
Explain about the exceptions of Android?

To create a custom exception in java you need to extend the Exception class.
Exceptions can be of two types :
1. Checked Exception
2. Unchecked Exception

Checked exception is checked at compile-time where as Unchecked exception is checked at runtime. 
Error comes under Unchecked exception .  

1

Exception:
Exception is an event that occur during the execution of program that disrupts the normal flow of them program. When an exception occur its object are created by the method in which an exception occurs, which is handle by the default exception handler. The object contains all the details of the exception and its type etc.
Exception Handler is a code that executes when exception is occurs. The run-time handler search the call stack to find the appropriate method containing the code for exception and after receive suitable solution then handle all the exception, and generate accurate message on the screen. Mostly exception class is the sub-class of Throwable class .

Type of Exception:
In Any programming language, there are basically two types of exceptions first is checked and another is unchecked where error is considered as unchecked exception.
  1.  Checked Exception (Compile Time Exception)
  2.  Unchecked Exception (Run Time Exception )
  3.  Error

Explain about the exceptions of Android?

Checked Exception:
Those exceptions are called checked exception which occur at compile time. So for this reason it is also called compile time exceptions. These types of exceptions cannot be ignored at the compile time, it should be necessary to handle it. If a program is throwing a checked exception at compile time then it should handle using try-catch block and declare the exception using throw keyword, otherwise the program will give a compilation error.
Example of checked Exception- FileNotFoundException.

Unchecked Exception
Those exceptions are called unchecked exception that are not handle at compile time. It means if your program is throwing an unchecked exception at run-time and even if you didn’t handle that exception then program won’t give a compilation error. Mostly these types of exception occurs due to the bad data provided by the user during the user-program interaction. It is also known as run time exceptions.
Some Example of unchecked Exception-
  • ArithmeticException,
  •  NullPointerException
  •  ArrayIndexOutOf BoundException
  •  IllegalArgumentException
  •  NumberFormatException etc.

Error
Error is an abnormal condition of the program that is ignored by the compiler, it is not an exception. Error class is derived from the Throwable class. Errors happen at run time. They will not be known to compiler.

Explain about the exceptions of Android?