5 Replies - 187 Views - Last Post: 03 October 2012 - 10:37 AM Rate Topic: -----

#1 bmckinn8  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-September 11

Exception handling

Posted 03 October 2012 - 09:48 AM

I have a method that throws two exceptions. I have a second method that calls the first in the try block. Does this second method need to have "throws Fit" in the method call(like I have it below)? Or, can I omit it.

method 1
public void foo() throws Up, Fit
{
   ...
}



method 2 calls method 1
public void callsFoo() throws Fit
{
     try
     {
          foo();
     }
     catch (Up u)
     {
          ...
     }
     catch (Fit f)
     {
          ...
          throw f;
     }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Exception handling

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1275
  • View blog
  • Posts: 2,837
  • Joined: 05-April 11

Re: Exception handling

Posted 03 October 2012 - 09:51 AM

You can remove it.

In java you will get a compile error if there is an exception you need to catch but doesnt :) Unless it is a RuntimeException
Was This Post Helpful? 0
  • +
  • -

#3 bmckinn8  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-September 11

Re: Exception handling

Posted 03 October 2012 - 09:56 AM

Would it be considered a "Good Practice" to leave it in?
Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1275
  • View blog
  • Posts: 2,837
  • Joined: 05-April 11

Re: Exception handling

Posted 03 October 2012 - 09:58 AM

View Postbmckinn8, on 03 October 2012 - 04:56 PM, said:

Would it be considered a "Good Practice" to leave it in?


If all you do with it is throw it, then I don't see a reason for you to catch it

You are already telling that you are going to throw the exception, so people are aware that it can happen :)
Was This Post Helpful? 2
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,102
  • Joined: 19-March 11

Re: Exception handling

Posted 03 October 2012 - 10:26 AM

One thing that you'll sometimes see is people catch an Exception, add a note to it, and throw it along, or else wrap it in some other Exception and throw that. This allows you to annotate the stack trace more effectively. For larger applications, this can be useful.
Was This Post Helpful? 2
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Exception handling

Posted 03 October 2012 - 10:37 AM

Never seen, or most probably, nver noticed such a practice :) It might effecticely be uselfull sometimes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1