Java 实例 - 链试异常

Java 教程 · 2019-02-11 11:11:36

以下实例演示了使用多个 catch 来处理链试异常:

Main.java 文件

public class Main { public static void main (String args[])throws Exception { int n=20,result=0; try{ result=n/0; System.out.println("结果为"+result); } catch(ArithmeticException ex){ System.out.println("发算术异常: "+ex); try { throw new NumberFormatException(); } catch(NumberFormatException ex1) { System.out.println("手动抛出链试异常 : "+ex1); } } } }

以上代码运行输出结果为:

发算术异常: java.lang.ArithmeticException: / by zero
手动抛出链试异常 : java.lang.NumberFormatException

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Microformats

Microformats

John Allsopp / friends of ED / March 26, 2007 / $34.99

In this book, noted web developer and long time WaSP member John Allsop teaches all you need to know about the technology: what Microformats are currently available and how to use them; the general pr......一起来看看 《Microformats》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具