Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tk.lslayer.temp;
- import java.util.ArrayList;
- import java.util.List;
- public class CustomErrorDemo {
- public String errorThrower() throws IndexOutOfBoundsException, NullPointerException {
- // List<String> myCoolList = null;
- List<String> myCoolList = new ArrayList<String>();
- // Select one of two lines, and uncomment any
- String string = myCoolList.get(100500); //This makes Exception, depends on selected line on top
- return string;
- }
- public void errorCatcher() throws MyCooleCustomException {
- try {
- this.errorThrower(); //Exception will be here
- } catch (Exception e) {
- //rethrowing, wrapped in our MyCoolecustomException
- throw new MyCooleCustomException("We cought an exception!", e);
- }
- }
- public static void main(String args[]) {
- CustomErrorDemo handler = new CustomErrorDemo();
- try {
- handler.errorCatcher();
- } catch (MyCooleCustomException e) {
- System.out.println(e.getMessage()); //We caught MyCooleCustomException
- //warning, "Information expert" violated
- System.out.println(e.getCause().getClass().toString()); //We show a class of caught exception
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement