zoukankan      html  css  js  c++  java
  • Error原生类型

    •表示错误对象
    –EvalError, URIError, RangeError, etc.
    •捕获方式:
    –try { …throw new Error(…) } catch(e) { … }
    –理论上可以throw出任意对象
    •Error对象IE和FireFox公有属性
    –message:错误信息


    Error浏览器特定属性
    •IE:
    –description:同message属性
    –number:错误编号,只有脚本引擎抛出的错误才有该属性
    •FireFox:
    –fileName:创建错误的文件
    –lineNumber:创建错误对象的行号
    –stack:创建错误时的堆栈信息


    html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        
    <title>Native Error Type</title>
        
    <script language="javascript" type="text/javascript" src="Error.js"></script>
    </head>
    <body>
        
    <script language="javascript" type="text/javascript">
            
    try
            {
                throwError();
            }
            
    catch(e)
            {
                var errorMsg 
    = ("Message: " + e.message + "\n");
                
                
    if (!e.stack) // IE
                {
                    errorMsg 
    += ("Description: " + e.description + "\n");
                    errorMsg 
    += ("Number: " + e.number);
                }
                
    else
                {
                    errorMsg 
    += ("Line Number: " + e.lineNumber + "\n");
                    errorMsg 
    += ("File Name: " + e.fileName + "\n\n");
                    errorMsg 
    += ("Stack Trace:\n" + e.stack);
                }
                
                alert(errorMsg);
            }
        
    </script>
    </body>
    </html>

    Error.js
    function throwError()
    {
        
    throw new Error("Custom Error");
    }

    function getNiceError()
    {
        var e 
    = Error.create("Error Message",
            {customMessage : 
    "Custom Message"});
        
        e.popStackFrame();
        
    return e;
    }
  • 相关阅读:
    Python2和python3的对比
    AirtestIDE学习(一)详解(跨平台的UI自动化编辑器)
    2021/2/18 一些概念笔记
    Django学习笔记(一)
    安装python第三方包时报错
    pycharm调试nodejs代码
    postman+jwt接口做各个环境接口测试(三)
    iOS------App之间传递数据的几种方式
    iOS------教你如何APP怎么加急审核
    关于苹果延迟了App接入HTTPS服务截止日期
  • 原文地址:https://www.cnblogs.com/timy/p/1181428.html
Copyright © 2011-2022 走看看