zoukankan      html  css  js  c++  java
  • java 中异常处理示例并捕获完整异常内容

    public class Test {
    
        public static void main(String[] args) 
        {
            try 
            {
                int a = 1;
                int b = 0;
                int c = a/b;
            } 
            catch(java.lang.Exception e)
            {
                StringWriter errors = new StringWriter();
                e.printStackTrace(new PrintWriter(errors));
                String errorMsg = errors.toString();
                System.out.println(errorMsg);
            }
        }
    }
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.EventListener;
    import java.util.List;
    
    public class Test {
        
        public static void main(String[] args) 
        {
            int a = 1;
            int b = 0;
            int c = 0;
            
            try
            {
                System.out.println("1");
                c = a / b;
                throw new IOException();
            }
            catch(FileNotFoundException e)
            {
                System.out.println("2");
            }
            catch(IOException e)
            {
                System.out.println("3");
            }
            catch(Exception e)
            {
                System.out.println("4");
                c = a / b;
            }
            finally
            {
                System.out.println("5");
            }
            
            System.out.println("6");
        }
  • 相关阅读:
    模块(相当于Java里的包)
    if_else_while_for
    用户交互
    Python入门
    BigInteger类及方法应用
    selenium+java破解极验滑动验证码的示例代码
    Postman 使用详解
    Postman用法简介
    伟大架构师的秘密【转载】
    深入理解HTTP协议(转)
  • 原文地址:https://www.cnblogs.com/nanfei/p/8351180.html
Copyright © 2011-2022 走看看