zoukankan      html  css  js  c++  java
  • JS中 try...catch...finally (转)

    JS的try..catch..finally

    var array = null;
    try {
        document.write(array[0]);
    } catch(err) {
        document.writeln("Error name: " + err.name + "");
        document.writeln("Error message: " + err.message);
    }
    finally{
        alert("object is null");
    }
    程序执行过程
    1. array[0]的时候由于没有创建array数组,array是个空对象,程序中调用array[0]就会产生object is null的异常 
    2. catch(err)语句捕获到这个异常通过err.name打印了错误类型,err.message打印了错误的详细信息. 
    3. finally类似于java的finally,无论有无异常都会执行.
     
    现总结Error.name的六种值对应的信息:
    1. EvalError:eval_r()的使用与定义不一致 
    2. RangeError:数值越界 
    3. ReferenceError:非法或不能识别的引用数值 
    4. SyntaxError:发生语法解析错误 
    5. TypeError:操作数类型错误 
    6. URIError:URI处理函数使用不当
  • 相关阅读:
    css
    js
    css3
    css
    深浅拷贝
    index-数据结构/算法
    es6知识点
    在vscode中配置sass savepath
    计算机基础
    element-ui使用后手记
  • 原文地址:https://www.cnblogs.com/jokerjason/p/7383768.html
Copyright © 2011-2022 走看看