Learning Java/Error handling II

Finally - Generating exceptions !
All exceptions are classes. To get you started, I will show you some code:

Notice the utter simplicity. This is the first part of making exceptions. In the constructor, it calls its super class, Exception. In printStackTrace it also calls the super class. The method printStackTrace will print the error message. Again, note the simplicity!

The second, harder part
What is the use of creating an exception class by itself? It isn't used anywhere... yet! We will make a class and method that throws this exception. We will name the class Use_Exceptions. The class will ask for an int through a window. It will convert the integer to a string and use the try/catch method to do the NumberFormatException. Then, it will throw this exception if the integer is negative. Again, some code:

The "new" creates a new AnotherException. "throw" throws it - executes the exception. Let's make something that uses this:

Just like the normal try/catch block!