Search This Blog

Loading...

Nov 12, 2010

How to use try catch block in JavaScript


Sponsored Links:
<script type="text/javascript">
document.write("My My value is " + myVariable);
</script>
image 
Above line will gives you an error because you have not defined the variable name. you can catch this error in try catch block as below
<script type="text/javascript">
try
{
document.write("My value is " + myVariable);
}
catch(err)
{
document.write("There is an undeclared variable ..but hey"+, 
"don't let that stop you!");
}
</script>

image

Follow by Email