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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jake Trent
March 19, 2014
Programming
110
0
Share
JavaScript Error Handling
Points mostly from a talk originally given at #MWRC by @xjamundx
Jake Trent
March 19, 2014
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
680
Getting into Frontend Dev Today
jaketrent
0
640
Encourage Great Combinations
jaketrent
0
830
Getting into React
jaketrent
0
750
Ways to Compose in React
jaketrent
0
92
Anatomy of a Blot Post
jaketrent
0
84
Voice of the Leaders
jaketrent
0
82
Other Decks in Programming
See All in Programming
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
890
GitHub Copilot CLIのいいところ
htkym
2
600
TSKaigi2026-静的解析への投資がAI時代のコード品質を支える ── カスタムESLintルールの設計と運用
hayatokudou
5
980
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
130
関係性から理解する"同一性"の型用語たち
pvcresin
2
480
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
120
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
140
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
170
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
580
20260514_its_the_context_window_stupid.pdf
heita
0
1.1k
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
220
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
130
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
530
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
150
Designing Powerful Visuals for Engaging Learning
tmiket
1
370
Mobile First: as difficult as doing things right
swwweet
225
10k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
230
A designer walks into a library…
pauljervisheath
211
24k
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