开发者

Node.js: Is it possible to catch a "TypeError" and keep the server up?

Somtimes I have a typerror in my code that crashes my server. I'm wondering if there's something I can add so it does not crashes after that happens. Here's more details to the crash:

2011-06-08T11:23:09+00:00 app[worker.1]: /app/lib/imap.js:1019
2011-06-08T11:23:09+00:00 app[worker.1]:         type: cur[0].toLowerCase(), subtype: cur[1].toLowerCase(),
201开发者_开发百科1-06-08T11:23:09+00:00 app[worker.1]:                                                     ^
2011-06-08T11:23:09+00:00 app[worker.1]: TypeError: Object FILENAME,Oportunidad especial de has no method 'toLowerCase'
2011-06-08T11:23:09+00:00 app[worker.1]:     at parseBodyStructure (/app/lib/imap.js:1019:53)
2011-06-08T11:23:09+00:00 app[worker.1]:     at parseBodyStructure (/app/lib/imap.js:1090:23)
2011-06-08T11:23:09+00:00 app[worker.1]:     at parseBodyStructure (/app/lib/imap.js:1000:18)
2011-06-08T11:23:09+00:00 app[worker.1]:     at parseBodyStructure (/app/lib/imap.js:994:13)
2011-06-08T11:23:09+00:00 app[worker.1]:     at parseFetch (/app/lib/imap.js:974:29)
2011-06-08T11:23:09+00:00 app[worker.1]:     at CleartextStream.<anonymous> (/app/lib/imap.js:180:11)
2011-06-08T11:23:09+00:00 app[worker.1]:     at CleartextStream.emit (events.js:64:17)
2011-06-08T11:23:09+00:00 app[worker.1]:     at CleartextStream._push (tls.js:285:31)
2011-06-08T11:23:09+00:00 app[worker.1]:     at SecurePair._cycle (tls.js:565:20)
2011-06-08T11:23:09+00:00 app[worker.1]:     at EncryptedStream.write (tls.js:97:13)
2011-06-08T11:23:09+00:00 heroku[worker.1]: Process exited
2011-06-08T11:23:09+00:00 heroku[worker.1]: State changed from up to crashed

Thanks


Handle the uncaughtException event on the process.

process.on('uncaughtException', function (err) {
  console.log('Oh shit recover somehow');
});

Warning: This will catch all exceptions. If you don't bother to handle them properly you can corrupt state very badly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜