The error objects created by constructors(Error(),  SyntaxError(), TypeError(), and others) have the following properties:

name

The name property of the constructor function that created the object; it could be the general “Error” or a more specialized constructor such as “RangeError”.

message

The string passed to the constructor when creating the object.

You can be creative when it comes to your custom error objects and use them to restore the application state back to normal.

try {

    // something bad happened, throw an error

    throw {

        name: "MyErrorType", // custom error type

        message: "oops",

        extra: "This was rather embarrassing",

        remedy: genericErrorHandler // who should handle it

    };

} catch (e) {

    // inform the user

    alert(e.message); // "oops"

    // gracefully handle the error

    e.remedy(); // calls genericErrorHandler()

}

JavaScript Patterns 3.8 Error Objects的更多相关文章

  1. JavaScript Patterns 4.9 Configuration Objects

    Configuration Objects Passing a large number of parameters is not convenient. A better approach is t ...

  2. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  3. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  4. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

  5. JavaScript Patterns 6.4 Prototypal Inheritance

    No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...

  6. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

    // the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...

  7. JavaScript Patterns 5.6 Static Members

    Public Static Members // constructor var Gadget = function (price) { this.price = price; }; // a sta ...

  8. JavaScript Patterns 5.3 Private Properties and Methods

    All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...

  9. JavaScript Patterns 5.1 Namespace Pattern

    global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { ...

随机推荐

  1. 3 Servlet监听器

    作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) 1. ServletConfig和ServletContext 1.1 ServletConfig和Servle ...

  2. [Solution] Microsoft Windows 服务(1) C#创建Windows服务

    Microsoft Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而 ...

  3. C#中国象棋+游戏大厅 服务器 + 客户端源码

    来源:www.ajerp.com/bbs C#中国象棋+游戏大厅 服务器 + 客户端源码 源码开源 C#版中国象棋(附游戏大厅) 基于前人大虾的修改版 主要用委托实现 服务器支持在线人数,大厅桌数的设 ...

  4. WinForm公共控件

    公共控件:1.Button:按钮 用户点击时触发事件 行为属性 Enabled -是否启用 Visible -是否隐藏2.CheckBox .CheckListBox - 复选框 复选框组 3.Com ...

  5. 互联网产品团队中Web前端工程师的重要性

    国内外各大互联网公司,都有UEx/d|UCD|CDC(Customer Research & User Experience Design Center)团队. 在很多公司会认为,合格的产品经 ...

  6. SpringMvc+Mybatis 框架搭建

    本文承接上一篇[idea使用maven搭建springmvc] 开篇:在main/resources下新建dbconfig.properties.spring.xml.spring-mybatis.x ...

  7. 后缀数组---New Distinct Substrings

    Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...

  8. 隐藏android系统标题栏和状态栏

    //隐藏系统title requestWindowFeature(Window.FEATURE_NO_TITLE); //隐藏状态栏 getWindow().addFlags(WindowManage ...

  9. mongodb学习5--mongo的type类型

    db.active.group({key:{id:1},cond:{cd:20160913,cid:"fgsdljsdv",aid:"54465"},reduc ...

  10. PHP学习笔记:利用gd库给图片打图片水印

    <?php $dst_path = '1.jpg';//目标图片 $src_path = 'logo1.png';//水印图片 //创建图片的实例 $dst = imagecreatefroms ...