Monday, February 18, 2013

JavaScript Error Handling


Debugging is quite unpleasant due to type-less nature of variables and run-time interpretation on a browser.

JavaScript uses try..catch blocks for catching that erroneously uses a variable as the wrong data type.

try
{
  var x = 1; //x is a number
  var xLength = x.length; //x now assumed to be a string or an array - will fail
}
catch(e){
  alert(e.message); //Display exception
}

Visual Studio has some JavaScript debugging support.

No comments:
Write comments
Recommended Posts × +