当前位置:网站首页>2022/07/30 学习笔记 (day20) 面试题积累
2022/07/30 学习笔记 (day20) 面试题积累
2022-07-30 21:42:00 【激进的黄瓜】
目录
4.三个字符串String StringBuffer StringBuilder的区别 :
随时学,随时加
1.throws和throw的区别:
throws:在方法后边声明异常,其实就是自己不想对异常做出任何的处理,告诉别人自己可能出现的异常,交给别人处理,然别人处理
package com.xinkaipu.Exception;
class Math{
public int div(int i,int j) throws Exception{
int t=i/j;
return t;
}
}
public class ThrowsDemo {
public static void main(String args[]) throws Exception{
Math m=new Math();
}
}
throw: 就是自己处理一个异常,有两种方式要么是自己捕获异常try...catch代码块,要么是抛出一个异常(throws 异常)
package com.xinkaipu.Exception;
public class TestThrow
{
public static void main(String[] args)
{
try
{
//调用带throws声明的方法,必须显式捕获该异常
//否则,必须在main方法中再次声明抛出
throwChecked(-3);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
//调用抛出Runtime异常的方法既可以显式捕获该异常,
//也可不理会该异常
throwRuntime(3);
}
public static void throwChecked(int a)throws Exception
{
if (a > 0)
{
//自行抛出Exception异常
//该代码必须处于try块里,或处于带throws声明的方法中
throw new Exception("a的值大于0,不符合要求");
}
}
public static void throwRuntime(int a)
{
if (a > 0)
{
//自行抛出RuntimeException异常,既可以显式捕获该异常
//也可完全不理会该异常,把该异常交给该方法调用者处理
throw new RuntimeException("a的值大于0,不符合要求");
}
}
}
2.代码块执行顺序:
代码块执行顺序:静态代码块——> 构造代码块 ——> 构造函数——> 普通代码块
继承中代码块执行顺序:父类静态块——>子类静态块——>父类代码块——>父类构造器——>子类代码块——>子类构造器
3.try ... catch、finally执行顺序:
finally永远是在最后执行的
如果在try ... catch语句中有return,
catch可以写多个异常(可以捕获多个异常)
顺序问题:先写小的,再写大的
4.三个字符串String StringBuffer StringBuilder的区别 :
边栏推荐
- ArrayList扩容机制分析
- JDBC (detailed explanation)
- It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)
- 大家都在用的plm项目管理软件有哪些
- 类和对象——上
- Solve npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead
- LeetCode·Daily Question·952. Calculate Maximum Component Size by Common Factor·Union Check
- 深入浅出富文本编辑器
- MYSQL JDBC图书管理系统
- 【问题】Mysql Waiting for table metadata lock 解决方案 修改lock_wait_timeout时间
猜你喜欢
[Deep Learning] Target Detection | SSD Principle and Implementation
手把手教你搭建一台永久运行的个人服务器
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
ClickHouse to create a database to create a table view dictionary SQL
The mysql time field is set to the current time by default
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
牛客小白月赛53 A-E
It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)
navicat无法连接mysql超详细处理方法
随机推荐
基于ABP实现DDD--实体创建和更新
Uni-app 小程序 App 的广告变现之路:激励视频广告
不用bs4的原因居然是名字太长?爬取彩票开奖信息
mysql remove duplicate data
Solve the problem of centos8 MySQL password ERROR 1820 (HY000) You must reset your password using the ALTER USER
基于ABP实现DDD--领域逻辑和应用逻辑
使用LVS和Keepalived搭建高可用负载均衡服务器集群
【问题】Mysql Waiting for table metadata lock 解决方案 修改lock_wait_timeout时间
navicat无法连接mysql超详细处理方法
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
Advanced c language: pointers (5)
The mysql time field is set to the current time by default
系统结构考点之并行主存
系统结构考点之多级混洗交换网络
系统结构考点之并行计算霍纳法则
Navicat连接MySQL时弹出:1045:Access denied for user ‘root’@’localhost’
go语言慢速入门——流程控制语句
【零代码工具】15 款企业级零代码开发平台推荐,总有一款是你心仪的
大家都在用的plm项目管理软件有哪些
Chrome 配置samesite=none方式