JavaScript Patterns 3.8 Error Objects
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的更多相关文章
- JavaScript Patterns 4.9 Configuration Objects
Configuration Objects Passing a large number of parameters is not convenient. A better approach is t ...
- 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 ...
- JavaScript Patterns 6.6 Mix-ins
Loop through arguments and copy every property of every object passed to the function. And the resul ...
- JavaScript Patterns 6.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
- JavaScript Patterns 6.4 Prototypal Inheritance
No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...
- JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance
// the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...
- JavaScript Patterns 5.6 Static Members
Public Static Members // constructor var Gadget = function (price) { this.price = price; }; // a sta ...
- JavaScript Patterns 5.3 Private Properties and Methods
All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...
- JavaScript Patterns 5.1 Namespace Pattern
global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { ...
随机推荐
- ssl 握手过程【收藏】
收藏几篇关于ssl handshake的好文 http://www.slashroot.in/comment/1242 SSL protocol, does its fantastic job of ...
- Android学习笔记之DocumentBuilder的使用....
PS:当你的才华还撑不起你的野心时,那你需要静下心来学习..... 学习内容: 1.从服务器上获取XML文档... 2.解析XML文档中的内容... XML文件想必大家都非常的熟悉,可扩展的标记语 ...
- Android学习笔记(第二篇)View中的五大布局
PS:人不要低估自己的实力,但是也不能高估自己的能力.凡事谦为本... 学习内容: 1.用户界面View中的五大布局... i.首先介绍一下view的概念 view是什么呢?我们已经知道一个Act ...
- 为了去重复,写了一个通用的比较容器类,可以用在需要比较的地方,且支持Lamda表达式
为了去重复,写了一个通用的比较容器类,可以用在需要比较的地方,且支持Lamda表达式,代码如下: public class DataComparer<T>:IEqualityCompare ...
- 另一个 OleDbParameterCollection 中已包含 OleDbParameter 错误分析及解决办法
程序非常简单,就是从一个表中取出一个符合要求的数据,如果取到,就把该数据对应的计数加1.也就是执行不同的两个SQL语句操作同一个表,并且这两个SQL的参数是一样的.在一个函数里完成这个调用.执行第二个 ...
- weblogic 12C 数据源配置出错的解决办法
驱动程序类名称: 11G 10.3.6与12G数据源配置有很大区别,整个一天才搞明白. 如有疑问可留言:http://www.cnblogs.com/endv/p/4110798.html 配 ...
- 怎样计算一个整数的位数&并把每一位上的数字保存下来
用循环来解决~~ M每次除以10, 再用一个变量count来计数,每循环一次 加1,直到这个数除去10后的数小于10 ,count再加1就可以了 实例:整数M=4325, 第一次:4325/10=43 ...
- java俄罗斯方块游戏代码
java俄罗斯方块游戏代码: package com; import java.awt.Color; import java.awt.Graphics; import java.awt.event.K ...
- 关于 hangfire 的权限问题
hangfire 是一个分布式后台执行服务. 官网:http://hangfire.io/ 我看中hangfire的地方是 1:使用简单 2:多种持久化保存方案.支持sqlserver ,msmq等 ...
- LeetCode126:Word Ladder
题目: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...