import java.awt.*;
//
// 定义 直男判断类
//
class StraightException extends Exception{
@Override
public String toString() {
return "你是一个直男!";
}
}
public class IsStraightMan{
/*
如果一个方法需要抛出异常:
1. 在定义时后缀就要添加 throw。
2. 在方法中需要使用 throw 一个新的异常
*/
static void Check(String x) throws StraightException{
if(x.equals("多喝热水")){
throw new StraightException();
}
}
static public void main(String args[]){
IsStraightMan x = new IsStraightMan();
try{
x.Check("多喝热水");
}catch (StraightException t){
System.out.println(t);
}
}
}