class Bar{int age;
public Bar(int age){
this.age = age;}voidcheck() throws IllegalArgumentException{if(age <18){
throw new IllegalArgumentException("年纪太小");}}}
public class Test {
public staticvoidmain(String[] args){
Bar b = new Bar(15);
try{
b.check();}catch(IllegalArgumentException e){
System.out.println(e.getMessage());
e.printStackTrace();}
System.out.println("end");}}
class Bar{int age;
public Bar(int age){
this.age = age;}voidcheck() throws ArgumentException{if(age <18){
throw new ArgumentException("年纪太小");}}}
class ArgumentException extends Exception{
private String message;
public ArgumentException(String message){
this.message = message;}}
public class Test {
public staticvoidmain(String[] args){
Bar b = new Bar(15);
try{
b.check();}catch(ArgumentException e){
System.out.println(e.getMessage());
e.printStackTrace();}
System.out.println("end");}}