-9

Is there an equivalent of try catch mechanism for client side(JavaScript) like the one we have for exception handling in C#.

What would be the best way to handle exceptions in client side.

ckv
  • 10,539
  • 20
  • 100
  • 144
  • 6
    maybe [try ... catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) – Stephen Thomas Mar 15 '14 at 16:44
  • 1
    I tried looking for a suitable reason to close this down, but there isn't one. – Andy Mar 15 '14 at 16:50
  • Try `try {}catch(e){}` then you can catch it – Fizer Khan Mar 15 '14 at 16:51
  • Actually, "looking for a resource" is the best fit. – Andy Mar 15 '14 at 16:51
  • Sorry for this. Just now downloaded the new iOS app and was excited to try it out. I apologise for this. Will delete this post – ckv Mar 15 '14 at 16:52
  • wow iOS and javascript are the same , your sharing your account with someone or they gave it to you, as your words do not match your history on questions – alexmac Mar 15 '14 at 16:59
  • I don't know what you are talking about. What I meant was I just downloaded the alpha version of stack exchange app and was too tempted to try it out. Sorry for the confusion – ckv Mar 15 '14 at 17:01
  • possible duplicate of [Javascript error handling with try .. catch .. finally](http://stackoverflow.com/questions/286297/javascript-error-handling-with-try-catch-finally) – Dheeraj Bhaskar Mar 15 '14 at 18:55

1 Answers1

4
try
  {
  //Run some code here
  }
catch(err)
  {
  //Handle errors here
  }

You can also throw exceptions as in c#

throw 'something went wrong !';

The exception can be a JavaScript String, a Number, a Boolean or an Object.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95