class Elliptical{
public int radiusA, radiusB;
public int sum = 100;
public void setRadius(int r){
if(r>99) throw new IllegalArgumentException();
radiusA = r;
radiusB = sum - radiusA;
}
}
Why doesn't the compiler complain that
public void setRadius() doesn't read
public void setRadius() throws IllegalArgumentException??? The method throws this error...
no throws in method signature when methods generates exception?
Moderator: admin
-
- Posts: 33
- Joined: Wed Nov 13, 2013 4:11 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: no throws in method signature when methods generates exception?
IllegalArgumentException is a RuntimeException, which does not need to be caught or declared in the throws clause.
You may want to read up more on checked and unchecked exception: http://javarevisited.blogspot.com/2011/ ... -java.html and
http://stackoverflow.com/questions/6115 ... xplanation
HTH,
Paul.
You may want to read up more on checked and unchecked exception: http://javarevisited.blogspot.com/2011/ ... -java.html and
http://stackoverflow.com/questions/6115 ... xplanation
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 8 guests