Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaScript Error Handling
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jake Trent
March 19, 2014
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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.5k
Accessibility in the Pluralsight Design System
jaketrent
0
760
Design System Support Beyond React
jaketrent
0
690
Getting into Frontend Dev Today
jaketrent
0
650
Encourage Great Combinations
jaketrent
0
900
Getting into React
jaketrent
0
770
Ways to Compose in React
jaketrent
0
120
Anatomy of a Blot Post
jaketrent
0
100
Voice of the Leaders
jaketrent
0
99
Other Decks in Programming
See All in Programming
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
220
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
780
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
180
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
AWSに止められる覚悟してますか?
morizo_1984
2
540
contenteditable と日本語入力に向き合う
colorful12
0
200
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
100
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
290
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
510
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
Featured
See All Featured
Are puppies a ranking factor?
jonoalderson
2
4.1k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Building Applications with DynamoDB
mza
96
7.2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Why Our Code Smells
bkeepers
PRO
340
58k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
The Language of Interfaces
destraynor
162
27k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Utilizing Notion as your number one productivity tool
mfonobong
4
620
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