/* There is a circle and a rectangle. You can obtain the area. If an invalid area value occurs, it is regarded as an error in obtaining the area. The problem is indicated by an exception. The basic program is designed. * // Custom exception class NoValueException extends RuntimeException {NoValueException (String message) {super (message) ;}} interface Shape {void getArea ();} class Rec implements Shape {private int len, wid; Rec (int len, int wid) // throws NoValueException {if (len <0 | wid <0) throw new NoValueException ("negative"); // note newelse {this. len = len; this. wid = wid;} public void getArea () {System. out. println (len * wid) ;}} class Circle implements Shape {private int redius; public static final double PI = 3.14; Circle (int redius) {if (redius <= 0) throw new NoValueException ("negative"); this. redius = redius;} public void getArea () {System. out. println (redius * PI);} class ExceptionTest {public static void main (String [] args) {// try // {Rec r = new Rec (3, 4 ); r. getArea (); //} // catch (NoValueException e) // {// System. out. println (e. toString (); //} Circle c = new Circle (-3); c. getArea ();}}Experience: Return to csdn after a long time of n. Find the familiar feeling again ~~