-2
package test2;

public class StringLargeException {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }    
}
Derlin
  • 9,572
  • 2
  • 32
  • 53
  • please follow the package naming conventions by reading https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html – 0xDEADBEEF Apr 12 '17 at 08:36

2 Answers2

0

Simple; put the following into some Test.java ... compile and run.

class MyException extends Exception {
   MyException(String message) { super(message); }
}

public static void main(String args[]) throws Exception {
  throw new MyException("you didnt see this one coming");
}
GhostCat
  • 137,827
  • 25
  • 176
  • 248
0
  1. make a class A that extends From Exception class
  2. make a constructor that you can pass a message to the class
  3. then when you want to throw the exception just type throw new A("Message");
Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34