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;
    }
  • 相关阅读:
    Leetcode 50.Pow(x,n) By Python
    Leetcode 347.前K个高频元素 By Python
    Leetcode 414.Fizz Buzz By Python
    Leetcode 237.删除链表中的节点 By Python
    Leetcode 20.有效的括号 By Python
    Leetcode 70.爬楼梯 By Python
    Leetcode 190.颠倒二进制位 By Python
    团体程序设计天梯赛 L1-034. 点赞
    Wannafly挑战赛9 C-列一列
    TZOJ Start
  • 原文地址:https://www.cnblogs.com/timy/p/1181428.html
Copyright © 2011-2022 走看看