throw exception 3 ?

来源:13-12 完善登录注册校验功能

慕神4535282

2020-10-23

老师,下午好,请教一个问题,

@PostMapping("/reset-password")
public ResponseDto resetPassword(@RequestBody MemberDto memberDto) throws BusinessException { // 同样是调用会抛出错误的函数,为何这一行加不加上 throws BusinessException , 在IDEA中都不会报错
    // 略
    // 重置密码
    memberService.resetPassword(memberDto);
}

public void resetPassword(MemberDto memberDto) throws BusinessException {
}

public void imageCode(@PathVariable(value = "imageCodeToken") String imageCodeToken, HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { // 同样是调用会抛出错误的函数,为何这一行不加上 throws Exception , 在IDEA中就会报错
   // 略
   ImageIO.write(challenge, "jpg", jpegOutputStream);
}

谢谢老师解答!

写回答

1回答

甲蛙

2020-10-26

同前面的问题,BusinessException继承自RuntimeException,所以自定义异常或是JDK自带异常,继承RuntimeException的,写或不写throws都可以

0
1
慕神4535282
非常感谢!
2020-10-26
共1条回复

Spring Cloud+ Vue前后端分离开发企业级在线视频系统

全网稀缺课程 市场热门项目+主流框架 一课掌握前后端技术

1743 学习 · 1698 问题

查看课程