当前位置:网站首页>Custom exception class myexception
Custom exception class myexception
2022-06-13 08:26:00 【aliven1】
- according to Exception Redefine the exception class
package java2;
public class MyException extends Exception{
// The unique identifier of the class
static final long serialVersionUID = -338751699244229948L;
public MyException(){
// Constructors 1
}
public MyException(String msg){
// Constructors 2
super(msg);
}
}
- Use custom exception classes MyException Throw an exception
class Student {
private int id;
// 2.throws: Automatically catch thrown exceptions
public void regist(int id) throws MyException{
if(id>0){
this.id=id;
}else{
// 1.throw: Throw an exception manually
throw new MyException(" The data you entered is negative !");
}
}
}
- try-catch Get exception class data
@Test
public void testStudent(){
Student s=new Student();
// 3.try-catch The location of the calling method catches an exception
try {
s.regist(-1114);
} catch (Exception e) {
// 4.getMessage Get unexpected string
System.out.println(e.getMessage());
e.printStackTrace();
}
}
边栏推荐
- filebeat采集日志到ELK
- Motiko basic syntax in dfinity (ICP) -8
- Several precise order receiving methods suitable for fresh food wholesale industry
- Methods of importing and exporting settings in Altium Designer
- 第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
- 从零开始-实现JpetStore网站-1-建立项目框架以及项目介绍
- When submitting the laravel admin form and using the required verification, an error is reported when the value is 0
- Rust writes near smart contract
- Logstash configuration reference article
- 水仙花升级版(自幂数)
猜你喜欢

JS - print 99 multiplication table of the for cycle case

Guidance process and service control

File upload question type

AcWing 1977. Information relay (base ring tree, parallel search set)

BD新标签页(BdTab)插件如何登入?

Wechat upload picture material interface

How can the small and medium-sized lighting industry make use of the digital transformation to stand out from the encirclement?

How about a well-known food material distribution information management system?

Is there any good management software to solve the problems faced by tea wholesalers

微服务项目搭建三:自动生成代码
随机推荐
Data accuracy problems caused by inconsistent data types during sum in MySQL
Buuctf web (V)
array_ Pop error: only variables should be passed by reference
Learning record 4:einops / / cudnn benchamark=true // hook
Request alarm: refer policy: strict origin when cross origin or reference site policy: no refer when downgrade
JS - for cycle case: Horse grain
Penetration problem (main directory, password explosion, database uploading Trojan horse)
Process and scheduled task management
微服务项目搭建二:数据库设计
anaconda下安装pytorch
JS - array de duplication in the array object case
微服务系统架构搭建一:环境搭建
Verify the word limit of textarea input box. Only prompt but no submission limit
微服务项目搭建三:自动生成代码
Bidirectional retransmission step experiment
Shell脚本常用开发规范
天猫商品详情接口,天猫商品优惠券接口,天猫api接口,天猫价格监控接口,天猫比价接口,品牌维权接口,天猫销量api接口,接口代码可对接数据分析业务,品牌维权,比价业务,行业分析业务接口代码分享
JS - max. of array cases
HCIP_ MGRE comprehensive experiment
【博弈论-完全信息静态博弈】 Nash均衡