- Java code
public OperatorIF buildOperator(String act)throws BadOperatorException{ if ("add".equalsIgnoreCase(act)) { return new AddOperatorImpl(); }else if ("sub".equalsIgnoreCase(act)) { return new SubOperatorImpl(); }else if ("div".equalsIgnoreCase(act)) { return new DivOperatorImpl(); }else if ("mul".equalsIgnoreCase(act)) { return new MulOperatorImpl(); }else { throw new BadOperatorException("Bad Operator!!"); } }
如图,代码不报错!
没有返回值,就解释!
------解决方案--------------------
throw exception表示程序异常结束,还要返回值作甚
------解决方案--------------------
------解决方案--------------------
抛出异常了