Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JavaScript Error Handling
Search
Jake Trent
March 19, 2014
Programming
0
110
JavaScript Error Handling
Points mostly from a talk originally given at #MWRC by @xjamundx
Jake Trent
March 19, 2014
Tweet
Share
More Decks by Jake Trent
See All by Jake Trent
How We Make The Design System
jaketrent
4
1.4k
Accessibility in the Pluralsight Design System
jaketrent
0
740
Design System Support Beyond React
jaketrent
0
670
Getting into Frontend Dev Today
jaketrent
0
630
Encourage Great Combinations
jaketrent
0
790
Getting into React
jaketrent
0
740
Ways to Compose in React
jaketrent
0
83
Anatomy of a Blot Post
jaketrent
0
77
Voice of the Leaders
jaketrent
0
78
Other Decks in Programming
See All in Programming
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
550
Codex の「自走力」を高める
yorifuji
0
1.2k
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
380
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
140
受け入れテスト駆動開発(ATDD)×AI駆動開発 AI時代のATDDの取り組み方を考える
kztakasaki
2
580
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
550
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
120
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
120
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
220
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
390
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
590
モダンOBSプラグイン開発
umireon
0
130
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
150
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
It's Worth the Effort
3n
188
29k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Visualization
eitanlees
150
17k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
180
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
250
Faster Mobile Websites
deanohume
310
31k
Music & Morning Musume
bryan
47
7.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Everyday Curiosity
cassininazir
0
160
Transcript
JAVASCRIPT ERROR HANDLING FROM A TALK BY @XJAMUNDX AT #MWRC
TRY/CATCH • Use for JSON.parse • Don’t use like a
Java programmer
DON’T THROW • Only as a last resort • Nothing
else you can do
THROW - TJ FONTAINE • throw for programmer errors (eg,
missing required parameter) • https://us- east.manta.joyent.com/ dap/public/drop/er2.htm
ALWAYS USE ERROR OBJECTS • Not simply strings • Errors
contains stack traces • Will provide debug value
CREATE CUSTOM ERRORS • Extend Error - still of type
Error • New, specific type • Can attach other helpful properties (eg, data associated at time of error) • Other standard properties in Appendix: https://us- east.manta.joyent.com/dap/public/drop/er2.htm
CREATE CUSTOM ERRORS (2) ! function SpecialError(message, specialInfo) { Error.captureStackTrace(this,
arguments.callee) this.message = message this.name = ‘SpecialError' this.specialInfo = specialInfo } ! SpecialError.prototype = Object.create(Error.prototype)
CALLBACK W/ ERROR • Common pattern in Node • If
action creates error, pass as first parameter in callback
CALLBACK W/ ERROR (2) function doManyThings(done) { doAsync(function (err, data)
{ if (err) return done(err) // … done(null, data) }) }
NAME ANONYMOUS FUNCTIONS • Provides name in stack trace
NAME ANONYMOUS FUNCTIONS (2) doSomethingWithCallback(function veryCallback() { // if I
throw an error, stack trace <3 })
DOMAINS AREN’T COOL • core team is not pushing the
concept • https:// nodefirm.hackpad.com/ Node-Error-Handling- Summit-uXFi4FUg8Td
MAKE ERRORS TO CLIENTS CONSISTENT • Pass all errors through
a common error serializer • Client can also handle consistently
MAKE ERRORS TO CLIENTS CONSISTENT (2) res.json(400, formatError(err))
USE EXPRESS DEFAULT ERROR HANDLER • Good catch-all • Avoid
potential infinite loop bug in Express
USE EXPRESS DEFAULT ERROR HANDLER (2) app.use(function (err, req, res,
next) { res.json(500, formatError(err)) })
ON(‘UNCAUGHTEXCEPTION’) SHOULD ALWAYS EXIT • Call process.exit() • Otherwise, stuff
hangs • Long-running process might never complete for client; wait for timeout • Resources can be leaked (eg, db connections)
ON(‘UNCAUGHTEXCEPTION’) SHOULD ALWAYS EXIT (2) process.on('uncaughtException', function(err) { hurryAndWriteYourWill(err) process.exit()
});
RESOURCES • MWRC SLIDES FROM @XJAMUNDX HTTPS://CLOUDUP.COM/IHRJZBVDIFZ ! •
CORE TEAM NOTES HTTPS://NODEFIRM.HACKPAD.COM/NODE-ERROR-HANDLING-SUMMIT-UXFI4FUG8TD ! • TJ FONTAINE ERROR HANDLING HTTPS://US-EAST.MANTA.JOYENT.COM/DAP/PUBLIC/DROP/ER2.HTM
https://speakerdeck.com/jaketrent/javascript-error-handling