SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Node.js 
Exception Handling 
Do it the right way 
Minh Hoang - http://minhhoang.de
Node.js 
• is a still a relatively new programming language 
• Node.js crashes for any ‘uncatch error’ 
• Most developers are confused when to use 
• try/catch 
• pass error to a callback 
• throw an error
error vs. exception 
• an error = an instance of the Error class 
• can be created 
• can be thrown 
• can passed to callback 
• a thrown error = an Exception
errors 
Operational Errors 
(run-time issue, not bug) 
Programmer Errors 
(bug) 
• out-of-memory 
• connection issues 
• timeout 
• server return 500 HTTP code 
• socket hang-up 
• no ‘undefined’ check 
• no callback for asynchronous 
function 
• object type error 
a correct code must be able to deal with operation error
Best Practices for dealing 
with operation errors 
• Always put asynchronous code into try/catch (otherwise Node.js 
crashes if uncaught error happens) 
• Synchronous code: return error. 
• ENONT error why trying to open a file: create file the first before read it 
• socket hang-up: write code to reconnect if needed 
• ready to deal with invalid JSON - using try/catch 
• retry with 5xx HTTP error 
• no idea how to deal with unthinkable/-solvable issue - such as 
ENOMEM: log the error and crash (intentionally)
Dealing with programmer 
errors 
• crash immediately 
• how: throw new Error(‘ehh’); 
…. if you have a restarter in place (like Bluemix) 
…. or just use: forever.js
• instead of ‘callback(result)’ use ‘callback(err, 
result)’ 
• because: either ‘result’ or ‘err’ is NULL!
Error class 
• has {name, message, stack} 
• if you create an Error instance manually, at least 
provide {name, message}
last chance… 
• use process.on(‘uncaughtException’, function() 
{<do_sth>}); —> Global Catch 
• it’s NOT recommended…but what if your app’s 
just crashed without leaving a trace?
Automated Test 
• Crucially important 
• start with unit-test for all modules 
• then integration test 
• no test, no CI, you are in the coding hell!
and … think about this
Function 
- write it the right way - 
• first argument ist error 
• last ist callback 
• use return (return callback(null, data); or 
return(err)
Sources 
• Error Handling in Node.js https:// 
www.joyent.com/developers/node/design/errors 
• Node.js Best Practices: http:// 
www.slideshare.net/the_undefined/nodejs-best-practices- 
10428790 
• Continuous Development: http:// 
blog.risingstack.com/continuous-deployment-of-node- 
js-applications/
“Either I will find a way, 
or I will make one” 
–Philip Sidney

Mais conteúdo relacionado

Mais procurados

Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applicationsjasonhaddix
 
Android Internship report presentation
Android Internship report presentationAndroid Internship report presentation
Android Internship report presentationvinayh.vaghamshi _
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validationMaitree Patel
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologiesElectron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologiesBethmi Gunasekara
 
What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? Shady Selim
 
Android Penetration testing - Day 2
 Android Penetration testing - Day 2 Android Penetration testing - Day 2
Android Penetration testing - Day 2Mohammed Adam
 
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Windows
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on WindowsHow to Install numpy, scipy, matplotlib, pandas and scikit-learn on Windows
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on WindowsVinita Silaparasetty
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging TechniquesWebStackAcademy
 
Training report on web developing
Training report on web developingTraining report on web developing
Training report on web developingJawhar Ali
 
Code Review Best Practices
Code Review Best PracticesCode Review Best Practices
Code Review Best PracticesTrisha Gee
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxvishal choudhary
 
Internship on web development
Internship on web developmentInternship on web development
Internship on web developmentRajendra Kandel
 
Log4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfLog4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfBrandon DeVault
 

Mais procurados (20)

Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applications
 
Exception handling
Exception handlingException handling
Exception handling
 
Best PHP Frameworks
Best PHP FrameworksBest PHP Frameworks
Best PHP Frameworks
 
Android Internship report presentation
Android Internship report presentationAndroid Internship report presentation
Android Internship report presentation
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologiesElectron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
 
Introduction to MERN
Introduction to MERNIntroduction to MERN
Introduction to MERN
 
What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How? What is Kotlin Multiplaform? Why & How?
What is Kotlin Multiplaform? Why & How?
 
Android Penetration testing - Day 2
 Android Penetration testing - Day 2 Android Penetration testing - Day 2
Android Penetration testing - Day 2
 
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Windows
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on WindowsHow to Install numpy, scipy, matplotlib, pandas and scikit-learn on Windows
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Windows
 
5 Important Secure Coding Practices
5 Important Secure Coding Practices5 Important Secure Coding Practices
5 Important Secure Coding Practices
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Training report on web developing
Training report on web developingTraining report on web developing
Training report on web developing
 
Code Review Best Practices
Code Review Best PracticesCode Review Best Practices
Code Review Best Practices
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptx
 
Angular vs. React
Angular vs. ReactAngular vs. React
Angular vs. React
 
Bug bounty
Bug bountyBug bounty
Bug bounty
 
Internship on web development
Internship on web developmentInternship on web development
Internship on web development
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
 
Log4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfLog4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdf
 

Destaque

Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Nicholas Zakas
 
Media A2 Evaluation Question 2
Media A2 Evaluation Question 2Media A2 Evaluation Question 2
Media A2 Evaluation Question 2jemmabbb
 
Making Mad Men more Agile | Agile on the beach | Sept 2015
Making Mad Men more Agile | Agile on the beach | Sept 2015Making Mad Men more Agile | Agile on the beach | Sept 2015
Making Mad Men more Agile | Agile on the beach | Sept 2015Project Director at MSLGROUP UK
 
Circolare n 3 fondo di garanzia
Circolare n 3 fondo di garanziaCircolare n 3 fondo di garanzia
Circolare n 3 fondo di garanziaRoma
 
Презентация проекта Дождь Lite
Презентация проекта Дождь LiteПрезентация проекта Дождь Lite
Презентация проекта Дождь LitePolina Kozlovskaya
 
Perencanaan parkir jts
Perencanaan parkir jtsPerencanaan parkir jts
Perencanaan parkir jtsYopi Sapa
 
Catering Eventos
Catering EventosCatering Eventos
Catering Eventoscasandracg
 
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...handsomehangove55
 
I lama i_domyhomework_presentation
I lama i_domyhomework_presentationI lama i_domyhomework_presentation
I lama i_domyhomework_presentationmrjonesbrgs
 

Destaque (20)

Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)
 
ADHD
ADHDADHD
ADHD
 
Macteam may2015 pt v7
Macteam may2015 pt v7Macteam may2015 pt v7
Macteam may2015 pt v7
 
Kefolonia Website Mock
Kefolonia Website MockKefolonia Website Mock
Kefolonia Website Mock
 
Media A2 Evaluation Question 2
Media A2 Evaluation Question 2Media A2 Evaluation Question 2
Media A2 Evaluation Question 2
 
Making Mad Men more Agile | Agile on the beach | Sept 2015
Making Mad Men more Agile | Agile on the beach | Sept 2015Making Mad Men more Agile | Agile on the beach | Sept 2015
Making Mad Men more Agile | Agile on the beach | Sept 2015
 
Case de mecânica
Case de mecânicaCase de mecânica
Case de mecânica
 
Circolare n 3 fondo di garanzia
Circolare n 3 fondo di garanziaCircolare n 3 fondo di garanzia
Circolare n 3 fondo di garanzia
 
Veneto turismo
Veneto turismoVeneto turismo
Veneto turismo
 
Powerpoint 1
Powerpoint 1Powerpoint 1
Powerpoint 1
 
創業管理:兼職創業者完整課程 Week 3
創業管理:兼職創業者完整課程 Week 3創業管理:兼職創業者完整課程 Week 3
創業管理:兼職創業者完整課程 Week 3
 
SEB wireframes
SEB wireframesSEB wireframes
SEB wireframes
 
Презентация проекта Дождь Lite
Презентация проекта Дождь LiteПрезентация проекта Дождь Lite
Презентация проекта Дождь Lite
 
Perencanaan parkir jts
Perencanaan parkir jtsPerencanaan parkir jts
Perencanaan parkir jts
 
Catering Eventos
Catering EventosCatering Eventos
Catering Eventos
 
Wishclubteamusa_russia
Wishclubteamusa_russiaWishclubteamusa_russia
Wishclubteamusa_russia
 
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...
New Orleans Saints and Academy Sports + Outdoors announce renewal of long-ter...
 
I lama i_domyhomework_presentation
I lama i_domyhomework_presentationI lama i_domyhomework_presentation
I lama i_domyhomework_presentation
 
Croazia turismo
Croazia turismoCroazia turismo
Croazia turismo
 
Francia PACA
Francia PACAFrancia PACA
Francia PACA
 

Semelhante a Node.js exception handling

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014Alex Kavanagh
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentationahmed sayed
 
Error handling in XPages
Error handling in XPagesError handling in XPages
Error handling in XPagesdominion
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
Owasp tds
Owasp tdsOwasp tds
Owasp tdssnyff
 
intro-to-eclipse.pdf
intro-to-eclipse.pdfintro-to-eclipse.pdf
intro-to-eclipse.pdfSajeev P
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptyjrtytyuu
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyWen-Tien Chang
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsGanesh Samarthyam
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscriptBill Buchan
 
Php Debugging from the Trenches
Php Debugging from the TrenchesPhp Debugging from the Trenches
Php Debugging from the TrenchesSimon Jones
 
Cross-platform logging and analytics
Cross-platform logging and analyticsCross-platform logging and analytics
Cross-platform logging and analyticsDrew Crawford
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in DjangoLoek van Gent
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is moreBen Lau
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgSam Bowne
 

Semelhante a Node.js exception handling (20)

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
 
Error handling in XPages
Error handling in XPagesError handling in XPages
Error handling in XPages
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Owasp tds
Owasp tdsOwasp tds
Owasp tds
 
intro-to-eclipse.pdf
intro-to-eclipse.pdfintro-to-eclipse.pdf
intro-to-eclipse.pdf
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscript
 
Php Debugging from the Trenches
Php Debugging from the TrenchesPhp Debugging from the Trenches
Php Debugging from the Trenches
 
Cross-platform logging and analytics
Cross-platform logging and analyticsCross-platform logging and analytics
Cross-platform logging and analytics
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in Django
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
 
43c
43c43c
43c
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
 

Último

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Último (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Node.js exception handling

  • 1. Node.js Exception Handling Do it the right way Minh Hoang - http://minhhoang.de
  • 2. Node.js • is a still a relatively new programming language • Node.js crashes for any ‘uncatch error’ • Most developers are confused when to use • try/catch • pass error to a callback • throw an error
  • 3. error vs. exception • an error = an instance of the Error class • can be created • can be thrown • can passed to callback • a thrown error = an Exception
  • 4. errors Operational Errors (run-time issue, not bug) Programmer Errors (bug) • out-of-memory • connection issues • timeout • server return 500 HTTP code • socket hang-up • no ‘undefined’ check • no callback for asynchronous function • object type error a correct code must be able to deal with operation error
  • 5. Best Practices for dealing with operation errors • Always put asynchronous code into try/catch (otherwise Node.js crashes if uncaught error happens) • Synchronous code: return error. • ENONT error why trying to open a file: create file the first before read it • socket hang-up: write code to reconnect if needed • ready to deal with invalid JSON - using try/catch • retry with 5xx HTTP error • no idea how to deal with unthinkable/-solvable issue - such as ENOMEM: log the error and crash (intentionally)
  • 6. Dealing with programmer errors • crash immediately • how: throw new Error(‘ehh’); …. if you have a restarter in place (like Bluemix) …. or just use: forever.js
  • 7. • instead of ‘callback(result)’ use ‘callback(err, result)’ • because: either ‘result’ or ‘err’ is NULL!
  • 8. Error class • has {name, message, stack} • if you create an Error instance manually, at least provide {name, message}
  • 9. last chance… • use process.on(‘uncaughtException’, function() {<do_sth>}); —> Global Catch • it’s NOT recommended…but what if your app’s just crashed without leaving a trace?
  • 10. Automated Test • Crucially important • start with unit-test for all modules • then integration test • no test, no CI, you are in the coding hell!
  • 11. and … think about this
  • 12. Function - write it the right way - • first argument ist error • last ist callback • use return (return callback(null, data); or return(err)
  • 13. Sources • Error Handling in Node.js https:// www.joyent.com/developers/node/design/errors • Node.js Best Practices: http:// www.slideshare.net/the_undefined/nodejs-best-practices- 10428790 • Continuous Development: http:// blog.risingstack.com/continuous-deployment-of-node- js-applications/
  • 14. “Either I will find a way, or I will make one” –Philip Sidney