/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java |
package com.mycompany.lab6.exceptions_calebfontenot;
@author
public class CircleWithCheckedException {
private double radius;
public CircleWithCheckedException() throws Exception
{
this(1.0);
}
public CircleWithCheckedException(double radius) throws Exception
{
if (radius < 0) {
throw new Exception("Radius cannot be negative.");
}
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) throws Exception {
if (radius < 0) {
throw new Exception("Radius cannot be negative.");
}
this.radius = radius;
}
@Override
public String toString() {
return "CircleWithCheckedException{" + "radius=" + radius + '}';
}
public static void main(String[] args) {
try {
System.out.println(new CircleWithCheckedException(5));
System.out.println(new CircleWithCheckedException(-5));
System.out.println(new CircleWithCheckedException(10));
} catch (Exception ex) {
System.err.println("an exception occured: " + ex.getMessage());
}
}
}