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
// your code here
} catch (ExcpetionType name) {
//exception code here
//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();
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Resources:
http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html
http://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html