小编Rya*_*ell的帖子

对多个 then 方法使用相同的 catch 块

鉴于:

  • NodeJS v0.10.25
  • 启用所有 Harmony 功能
  • "use strict"

以及以下代码:

   db.connect({
      host: DB_HOST,
      port: DB_PORT
    }).then(function(dbConn) {
      console.log('DBASE connected to ' + DB_HOST + ':' + DB_PORT);
      db.dbList().run(dbConn).then(function(result) {
        if (result.indexOf(SCRIPT_NAME) == -1) throw new Error('unable to locate database ' + SCRIPT_NAME);
        dbConn.use(SCRIPT_NAME);
        console.log('DBASE bound to ' + SCRIPT_NAME + ' on ' + DB_HOST + ':' + DB_PORT);
        db.tableList().run(dbConn)
          .then(function(result) {
            if (!result) throw new Error(SCRIPT_NAME + ' unable to enumerate tables');
            if (!result.length) throw new Error(SCRIPT_NAME + ' has …
Run Code Online (Sandbox Code Playgroud)

error-handling catch-block node.js promise

1
推荐指数
1
解决办法
1319
查看次数

标签 统计

catch-block ×1

error-handling ×1

node.js ×1

promise ×1