Let's say you have a Servlet or a Web Service (a java application running on a server) and a client that wants to use a method on that server. If something goes wrong on the server, you might want to throw an exception, your code will look like this:
It's not such a good example, but it's the only one i can come up with I hope this puts you on the right track.
There are times when it makes sense for a program to deliberately throw an exception. This is the case when the program discovers some sort of exceptional or error condition, but there is no reasonable way to handle the error at the point where the problem is discovered. The program can throw an exception in the hope that some other part of the program will catch and handle the exception.
abalfazl hossein wrote:Why isn't Necessary for Error or RuntimeException?
Because RuntimeException and any other exceptions that subclass RuntimeException are unchecked exceptions. See Lesson: Exceptions in Sun's Java Tutorials to learn more about the difference between checked and unchecked exceptions.