Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't JavaScript libraries use error handling

I have looked through underscore.js and backbone.js, both two very popular libraries and noticed that they don't use error handling (try, catch, exception).

What is the reason for this decision?

like image 863
dev.pus Avatar asked Jul 15 '12 16:07

dev.pus


2 Answers

Actually when you write quality javascript code you don't really need try/catch. Exceptional logic is handled through if conditions and error handlers instead of catching exceptions at runtime.

like image 68
Darin Dimitrov Avatar answered Oct 03 '22 13:10

Darin Dimitrov


A quick look at these libraries does reveal several uses of throw and catch, so they do use exceptions, albeit sparingly.

Exceptions are useful where extra parameters could make functions cumbersome and unreadable and/or 'normal' preconditions for running the code have been badly broken beyond a predictable error case.

It seems a bit confusing to use the term 'error handling' as if you avoid exceptions but pass back an error value from a function this is still error handling.

like image 25
FruitBreak Avatar answered Oct 03 '22 13:10

FruitBreak