A lot of books and tutorials say things along the lines of: "The Java runtime system requires that a method either catch or specify all checked exceptions that can be thrown by that method" But I can write classes without throwing or catching anything..... ?
Joined: Sep 20, 2003
Yes you can write. But if your class using any of Java class methods which throws checked exceptions then you need to catch them or throw them back.
Joined: Mar 24, 2005
The reason you can write classes and methods without worrying about exceptions is that you have not yet encountered an exception that must be handled. Try to compile the following piece of code:
and see what happens...
Joined: Feb 11, 2006
Due to heavy use of checked exceptions and minimal use of unchecked exceptions, there has been a hot debate in the Java community regarding true value of checked exceptions. Use checked exceptions when the client code can take some useful recovery action based on information in exception. Use unchecked exception when client code cannot do anything. For example, convert your SQLException into another checked exception if the client code can recover from it and convert your SQLException into an unchecked (i.e. RuntimeException) exception, if the client code cannot do anything about it.