try/catch/finally

How to Write try/catch/finally to catch an Exception

1. In your MainActivity.java file, add the below code to the onCreate method.

try {
    // your code here
} catch (ExcpetionType name) {
    //exception code here
}

2. Replace the ExcpeptionType with the exception type that you need. Here are some examples.
// import java.io.IOException;
} catch (IOException e) {
    e.printStackTrace();

} catch (FileNotFoundException e) {
    e.printStackTrace();
}
Related Articles:

Resources:
http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html
http://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html