·

抛 Exception吧

Exceptions should be thrown when the contract between a method and its caller cannot be fulfilled. This is the usage identified in the Java™ Language Specification.

抛出异常不是严格禁止的事情,如果在项目结构中需要处理“函数分内的事情”则不需要抛出异常如果是“分外”的事情,则需要抛出异常。

Replies
3

抛的异常种类很多怎么办?比如很多种错误类型

如果是人为主动抛出的异常,那就返回errorcode和message。如果是系统抛出的异常,那就返回500,message是未知异常,最好再带一个requestid,可以回溯这一次请求。