Q&A

Q1:

Is it possible to create your own exceptions?

A1:

You can create your own exceptions easily by making them a subclass of an existing exception, such as Exception, the superclass of all exceptions. In a subclass of Exception, there are only two methods you might want to override: Exception() with no arguments and Exception() with a String as an argument. In the latter, the string should be a message describing the error that has occurred.

Q2:

Why doesn't this hour cover how to throw and catch errors in addition to exceptions?

A2:

Java divides problems into Errors and Exceptions because they differ in severity. Exceptions are less severe, so they are something that should be dealt with in your programs using try-catch or throws. Errors, on the other hand, are more serious and can't be dealt with adequately in a program. Two examples of these errors are stack overflows and out-of-memory errors. These can cause the Java interpreter to crash, and there's no way you can fix them in your own program as the interpreter runs it.

Q3:

In the children's song "This Old Man," what does the old man play knick-knack on when he reaches the number 12?

A3:

The rhymes vary in the song, which originated in the North Country of England during the 18th century. Some singers even vary the chorus, turning "knick-knack patty-whack" into "nick-nack cadillac." The old man begins with "he plays two, he plays knick-knack on my shoe," then moves on to the following things: three, knee; four, door or floor; five, hive or drive; six, bricks or sticks; seven, heaven or oven; eight, gate or plate; nine, line or all the time; and ten, hen or now and then. If he reaches 12, rhyming dictionaries offer only two decent possibilities for the old man: shelf or himself. Because the latter choice would give the song an R rating, it's safe to conclude that he plays knick-knack on my shelf with a knick-knack, paddy whack, give the dog a bone, then goes rolling home.

      
Comments