javaprintstacktrace

How to provoke an error in my program to display the printstacktrace


How do I provoke an error so that the exc.printStackTrace(System.out); is displayed when I run the program:

public String getName(){
    try {
        if(haveName()) return Name;
        else {
            throw new CorrectNameException("no name");
        }
    } catch (ExistException e) {
        return e.getExc();
    } catch (CorrectNameException exc) {
        exc.printStackTrace(System.out);
        return "nameless";
    }
}

Solution

  • Make haveName() return false. Simple.