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!");
    }

    }

  • 相关阅读:
    Codeforces 716C[数论][构造]
    HDU 5808[数位dp]
    Codeforces 611d [DP][字符串]
    Codeforces 404D [DP]
    HDU 5834 [树形dp]
    HDU 5521 [图论][最短路][建图灵感]
    矩阵
    kruskal 处理最短路 问题 A: 还是畅通工程
    Dijastra最短路 + 堆优化 模板
    CodeForces
  • 原文地址:https://www.cnblogs.com/batman425/p/4105162.html
Copyright © 2011-2022 走看看