Thread: exceptions
View Single Post
Join Date: Dec 2007
Posts: 1,664
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: exceptions

 
0
  #4
Feb 28th, 2008
  1. public void foo() throws Exception {
  2. //something happens and an exception is being thrown
  3. }
With the throws you don't avoid the exception. By adding throws you don't have to catch it, but it is thrown to the method that calls foo. Meaning that you have to write something like this:
  1. public void hoo() {
  2. try {
  3. foo();
  4. } catch (Exception e) {
  5. }
  6. }
You can omit try-catch by adding throws Exception at the declaration of hoo() but you don't avoid it because it is thrown to the one that calls hoo(). You can do that until you reach main() where you will eventually have to catch it in the end
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote