Java:
[ try] , . ( , , .)
- . new Exception(), . throw new Exception(), , try-catch, .
, try-catch, (). , , catch . try-catch, , . try-catch , , - ( ).
, - . ( ).
throws , , , , checked ( ). , throws throw. , , .
, , , , .
- , , , / .
public CircleWithException() throws InvalidRadiusException {
this(1.0);
}
CircleWithException() InvalidRadiusException (, (1.0) InvalidRadiusException.)
, , :
try {
new CircleWithException();
} catch (InvalidRadiusException e) {
}
, - , Exception
public class InvalidRadiusException extends Exception {
private double radius;
public InvalidRadiusException(double radius) {
super("Invalid radius " + radius);
this.radius = radius;
}
public double getRadius() {
return radius;
}
}
, /. Java , .
, InvalidRadiusException, :
throw new InvalidRadiusException(1.0);