Comments (2)
EventEmitter的实例去监听错误官网推荐的第一种方法,是基于一个前提,那就是必须主动emit('error')事件,然后才可以监听。事实上,真实项目中有太多的意外,比如三层以上回调中有个未定义变量,数据库连接失败,数组越界等这些情况,你无法在每一层去检查所有可能的错误并主动往最上一级发送错误事件。唯一的选择就是服务器自动挂掉了。
可是,很多时候,比如数组越界,可能是浏览器传入参数有问题,我们只想对当前用户停止服务,服务器不应该挂掉。这就是要求必须有个最外层调用者的try-catch,用以区分对待。目前来看,还没有什么原生支持,可以完全替代domains的作用。
不过ES7的async, await可以一定程度上实现
from node-interview-questions.
感谢回答
from node-interview-questions.
Related Issues (10)
- 代码演示 1) 原型链法 HOT 3
- 一点点疑问 HOT 1
- nextTick() priority over setImmediate()
- 关于继承这里 HOT 1
- 还有一个比较常被问到的问题 HOT 1
- 继承 //构造器应用法 HOT 1
- setImmediate 和 nextTick 的优先级 HOT 2
- 第一个关于执行顺序是错的 HOT 1
- 关于NodeJS全局变量的问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-interview-questions.