Exception ‘java.lang.Exception’ is never thrown in the method less
异常描述
- 使用 IDEA 开发过程中发现已有方法上抛出异常,但是异常代码的颜色是浅灰色的,鼠标移到代码上提示上述异常
Exception ‘java.lang.Exception’ is never thrown in the method less… (Ctrl+F1)
This inspection reports exceptions that are declared in a method’s signature but never thrown by the method itself or its implementations/derivatives. Since this inspection requires global code analysis, it is only available in batch inspection mode. A limited version for use in editor highlighting is available as General | Redundant throws declaration.
异常分析
- 方法中不需要抛出异常,因为没有需要抛出异常的代码
- 在 call() 方法上显示的抛出异常,但是 call() 方法内部却并无异常抛出,也没有会出现异常的代码内容
异常反思
- 开发过程中从底层编码开始需要向上抛出异常,异常交给 Controller 层进行处理
本文探讨了在使用IDEA开发过程中遇到的异常情况,即方法签名中声明的异常实际上并未在方法内抛出。这种情况通常由底层编码异常处理不当引起,导致Controller层异常处理逻辑混乱。文章深入分析了异常原因,并提供了相应的解决方案。
1457

被折叠的 条评论
为什么被折叠?



