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() { ...
随机推荐
- 一秒钟生成自己的iOS客户端
原谅我这个标题党 想当年我也是亲自学过几天Objective-c的程序猿,我一眼就知道我是在骗人,但那有怎样呢!还不是满大街都是各种<十分钟让你明白Objective-C的语法>.< ...
- Criteria查询数据
Criteria介绍: Criteria查询是Hibernate提供的一种查询方式,与HQL基于字符串的查询形式完全不同.Hibernate提供了org.hiberanee.Criteria 接口.o ...
- URL与图像格式
绝对/相对URL “绝对URL”是指资源的完整的地址,通常以“http://”打头: “相对URL”是指Internet上资源相对于当前页面的地址,它包含从当前页面指向目标资源位置的路径,不以“htt ...
- ASP.NET的路由
之前在探讨ASP.NET MVC的路由时,无意发现原本ASP.NET也有路由机制的.在学习MVC的路由时觉得这部分的资料不太多,不怎么充实(也许是我不懂得去看微软的官方文档).后来也尝试一下ASP. ...
- 自学silverlight 5.0
这是一个silverlight游戏:http://keleyi.com/keleyi/phtml/silverlight/ 接了个单子,非要用Silverlight 5来作一个项目,之前从来没接触过这 ...
- Java知识点总结(不定时更新)
1.基于分代的垃圾收集算法 设计思路:把对象按照寿命长短来分组,分为年轻代和年老代,新创建的对象被分在年轻代,如果对象经过几次回收后仍然存活,那么再把这个对象划分到年老代.年老代的收集频率不像年轻代那 ...
- Python入门笔记(26):Python执行环境
一.python特定的执行环境 在当前脚本继续进行 创建和管理子进程 执行外部命令或程序 执行需要输入的命令 通过网络来调用命令 执行命令来创建需要处理的输出 动态生成Python语句 导入Pytho ...
- 大话设计模式-->模板方法设计模式
在学习java的过程中,我们肯定听到过设计模式这名词,在行业中有这么一句话,若您能熟练的掌握23种设计模式,那么你便是大牛! 好了,废话不多说,今天我跟大家分享一下23种设计模式之一的 模板方法 设 ...
- c# tcp备忘及networkstream.length此流不支持查找解决
服务端 bool isRunning = true; MouseKeyBoard mk = new MouseKeyBoard(); void InitTcpServer(int port) { T ...
- C#中弹出文件选择窗体和判断是否下载提示窗体的源码
1.创建一个window窗体