/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/CircleWithCheckedException.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.lab6.exceptions_calebfontenot;

/**
 *
 * @author calebfontenot
 */
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());
        }
        
    }
}