Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

override of exception

 
nil lin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first,we can use "throws" to throw exception,
only checked exception can be override,right?
then, there are two rules for override,
how to explain those rules?
thanks a lot!!*^^*
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
The term "override" isn't normally used to describe anything to do with exceptions, and I'm afraid I've got no idea what you mean by "two rules." Perhaps you could explain your question a bit more, and perhaps include code if that would help.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me take a stab at it. There are basically two types of exceptions you'll run into, "java.lang.Exception" and "java.lang.RuntimeException".
They function the same way in most respects. You can create your own exception classes that extend either one of them, and if you throw them in a method you have to include it in the "throws ..." clause in the method header.
The major difference is that if you call a method that throws something that subclasses "java.lang.Exception", it MUST be referenced inside of a try/catch block. If you call a method that throws something that subclasses "java.lang.RuntimeException," you do not have to catch it.
Look in the Java API documentation staring at java.lang.Throwable and from there you can navigate to "Exception" and "RuntimeException" to read more about it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic