javascript - what should i use try and catch block or onerror event -


i new javascript.sometimes error comes in program after reviewing many times mistake still unsolved.tough mistakes small in sight .so away shall use event onerror or try catch block .which practice doing .

or there way find out mistake or error in program in less time..

please let me know..

it not 1 better other. situation, feel onerror easy , appropriate, lets alert error message reported javascript without needing rewrite code within try/catch blocks.

demo code onerror handler in self-contained script added above rest of page's code, along example syntax error triggers prompt showing javascript error message.

<script> onerror = function(m) {     return confirm(         'scripts on page generated error message: ' +          m +         '\n\ndo wish continue running scripts?'); } </script>  <script> alert(' hello'; </script> 

the above bad code generates alert message 'unexpected token ;' because of missing parenthesis.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -