IO流_try...catch的方式处理异常1

来源:互联网 发布:汇率查询软件 编辑:程序博客网 时间:2024/04/29 07:02
package cn.itcast_02;/* * 我们自已如何处理异常呢? * A:try...catch...finally * B:throws抛出 *  * try...catch...finally的处理格式: * try{ * 可能出理问题的代码; * }catch(异常名变量){ * 针对问题的处理 * }finally{ * 释放资源; * } *  * 变形格式: * try{ * 可能出现问题的代码 * }catch(异常名变量){ * 针对问题的处理 * } *  * 注意: * A:try里面的代码越少越好。 * B:cathc里面必须有内容,那怕是给出一个简单的提示。 */public class ExceptionDemo {public static void main(String[] args) {int a = 10;int b = 0;// System.out.println(a / b);try {System.out.println(a / b);} catch (ArithmeticException ae) {System.out.println("除数不能为零");}System.out.println("over");}}

0 0