Javascript Error Handling

Javascript Error Handling

When a you run a piece of code and it stops unexpectedly it means there is an Error. You can hanle Error by using try, catch, throw and finally statements.


Errors can be coding errors made by the programmer, errors due to wrong input, or with any other things.

Javascript Try and Catch

try
{
    Block of code to try
}
catch(error) 
{
    Block of code to handle errors
} 
finally 
{
    Block of code to be executed regardless of the try / catch result
}

try statement is used to test codes for errors.

catch statement is used to handle for errors.

throw statement is used to create custom errors.

finally statement is used to execute code, after try and catch.

Previous

Subscribe Our Newsletter And Get Tutorials
And Offers Via Email

Subscribe Our Newsletter And Get Tutorials And Offers Via Email