Try & Catch - How do you use them effectively?

I tried to teach myself JavaScript, and one thing I read was the try / catch structure. Unfortunately, the tutorial does not contain many explanations about how this would be useful, just how to set it up. Can someone give an idea?

+4
source share
2 answers

The MDC try ... catch documentation contains some compelling examples that you should follow.

+4
source

If this is an intensive function, I would not recommend using try -catch. You can refer to this document for a good explanation: http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices#Don.27t_use_try-catch-finally_inside_performance-critical_functions

Basically, it creates a second activation object in the context chain, and therefore your search takes longer.

+1
source

Source: https://habr.com/ru/post/1307314/


All Articles