当前位置:网站首页>自定义异常类的使用
自定义异常类的使用
2022-07-30 05:39:00 【北木桥溪】
自定义异常类
package com.cy.pj.common.exception;
/**自定义业务异常*/
public class ServiceException extends RuntimeException{
private static final long serialVersionUID = -5598865415547474216L;
public ServiceException() {
}
public ServiceException(String message) {
super(message);
}
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
public ServiceException(Throwable cause) {
super(cause);
}
public ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
//UnKnownAccountException
//
}
自定义异常类在serviceimpl中的使用
@Override
public int updateObject(SysRole entity, Integer[] menuIds) {
if (entity==null)
throw new IllegalArgumentException("保存对象不能为空");
if (StringUtils.isEmpty(entity.getName()))
throw new IllegalArgumentException("角色名不能为空");
if (menuIds==null||menuIds.length==0)
throw new ServiceException("必须为角色分配权限");
int rows = sysRoleDao.updateObject(entity);
if (rows==0)
throw new ServiceException("记录可能已经不存在");
sysRoleMenuDao.deleteObjectsByRoleId(entity.getId());
sysRoleMenuDao.insertObjects(entity.getId(), menuIds);
return rows;
}
边栏推荐
- Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
- net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
- MySQL Soul 16 Questions, how many questions can you last?
- Prime numbers (Tsinghua University computer test questions) (DAY 86)
- [Other] DS5
- 面试前需要巩固的算法知识点(自用,更新中)
- Numpy 中 np.vstack() 和 np.hstack() 简单解析
- 多线程并发服务器
- CISP-PTE Zhenti Demonstration
- 报错:npm ERR code EPERM
猜你喜欢

Graphic mirror symmetry (schematic diagram)

0基础玩转C语言—初识C语言(上)

面试前需要巩固的算法知识点(自用,更新中)
![[Image detection] Research on cumulative weighted edge detection method based on grayscale image with matlab code](/img/c1/f962f1c1d9f75732157d49a5d1d0d6.png)
[Image detection] Research on cumulative weighted edge detection method based on grayscale image with matlab code

50道SQL练习题(刷完直接进大厂)

C语言:快速排序三种方法(递归)

MySQL 用户授权

It is enough for MySQL to have this article (37k words, just like Bojun!!!)

navicat无法连接mysql超详细处理方法

初识C语言
随机推荐
My first understanding of MySql, and the basic syntax of DDL and DML and DQL in sql statements
MySql fuzzy query Daquan
650.只有两个键的键盘(动态规划)
net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.
Teach you how to design a CSDN system
417.太平洋大西洋水流问题
SRA数据下载方法总结
C语言必会15个文件函数
MySQL 数据库基础知识(系统化一篇入门)
MySQL-Explain详解
VS2022中关于scanf函数报错解决方法
MySQL stored procedure
C语言自定义类型一网打尽(结构体、位段/位域、枚举、联合体)
【C语言】三子棋(井字棋)的实现
131.分割回文串
453.最小操作数使数组元素相等
Qt实现单击或双击QTableWidge/View表头进行排序
cross_val_score的用法
argparse —— 命令行选项、参数和子命令解析器
空杯心态,知行合一