Giter Club home page Giter Club logo

Comments (2)

jimuyouyou avatar jimuyouyou commented on July 25, 2024

EventEmitter的实例去监听错误官网推荐的第一种方法,是基于一个前提,那就是必须主动emit('error')事件,然后才可以监听。事实上,真实项目中有太多的意外,比如三层以上回调中有个未定义变量,数据库连接失败,数组越界等这些情况,你无法在每一层去检查所有可能的错误并主动往最上一级发送错误事件。唯一的选择就是服务器自动挂掉了。

可是,很多时候,比如数组越界,可能是浏览器传入参数有问题,我们只想对当前用户停止服务,服务器不应该挂掉。这就是要求必须有个最外层调用者的try-catch,用以区分对待。目前来看,还没有什么原生支持,可以完全替代domains的作用。

不过ES7的async, await可以一定程度上实现

from node-interview-questions.

coolzc avatar coolzc commented on July 25, 2024

感谢回答

from node-interview-questions.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.