posted 16 years ago
Keyword throw is used to, well, throw an exception, which can be either checked or unchecked (RuntimeException). Whenever a checked exception is thrown (either explicitly, or calling some method that might throw it), the method has to either:
1) handle the exception in a catch { }, or
2) declare to throw that exception via the keyword throws
Unchecked (runtime) exceptions need not be declared with throws.
Which of the two you need to do in a specific method depends on the responsibilities: which part of the program is responsible for handling what kind of exception. When you declare with throws, the method is saying: "anybody calling me should know that I may throw exceptions such and such, so take due measures". The calling method will either handle it or let it propagate further up the call stack.