throws 使用在函数上, 后面跟的是异常类.可以跟多个,用逗号隔开
throw使用在函数内, 后跟的是异常对象
class Demo {
public int div(int a, int b) throws NegativeException { if (b < 0) { throw new NegativeException("除数是负数了"); } return a / b; } }本文共 246 字,大约阅读时间需要 1 分钟。
throws 使用在函数上, 后面跟的是异常类.可以跟多个,用逗号隔开
throw使用在函数内, 后跟的是异常对象
class Demo {
public int div(int a, int b) throws NegativeException { if (b < 0) { throw new NegativeException("除数是负数了"); } return a / b; } }转载于:https://blog.51cto.com/crayworklife/1035483