zoukankan      html  css  js  c++  java
  • java之异常

    package com.text.exception;

    class Test{
    void add(int a,int b) throws Exception
    {
    int c;
    c=a/b;
    System.out.println(a+"/"+b+"="+c);
    }
    }
    class DefaultException extends Exception
    {
    public DefaultException(String msg){
    //调用Exception类的构造方法,存入异常信息
    super(msg);
    }
    }
    public class TestException {

    /* static void add(int a,int b) throws Exception
    {
    int c;
    c=a/b;
    System.out.println(a+"/"+b+"="+c);
    }
    */
    public TestException() {
    // TODO Auto-generated constructor stub
    }

    /**
    * @param args
    */
    public static void main(String[] args){
    // TODO Auto-generated method stub
    //add(4,0);
    try{
    throw new DefaultException("自定义异常!");
    }
    catch(Exception e){
    System.out.println(e);
    }
    /* Test t = new Test();

    try{
    t.add(5, 0);
    }
    catch(Exception e){
    System.out.println("异常:"+e);
    } */
    // int arr[] = new int[5];
    // try{
    // arr[6] = 10;
    // }
    // catch(Exception e){
    /* catch(ArrayIndexOutOfBoundsException e){
    System.out.println(e.getMessage().toString());
    System.out.println("异常:"+e);
    System.out.println(e.getLocalizedMessage());
    }
    */

    System.out.println("end of main() method!");
    }

    }

  • 相关阅读:
    树世界
    清空 NumericUpDown
    没有评论的日子
    GetData.cs

    Hashtable 在程序中控制重复项
    Convert.ToInt32() VS System.Int32.Parse()
    饮食九要素
    添加 or 修改 的一个处理方式
    一个关于 电话号码 的正则表达式
  • 原文地址:https://www.cnblogs.com/batman425/p/4105162.html
Copyright © 2011-2022 走看看