Articles → JavaScript → Exception Handling In Javascript

Exception Handling In Javascript






What Are Exceptions?





Benefits Of Handling Exceptions





Syntax


try {
    //  Write your code here
} catch (e) {
    //  Write error handling code here
}



Try Catch In Javascript








try {
    document.getElementById('aa').value = 'test value';
} catch (e) {
    alert(e);
}

Try It



Picture showing the alert box showing the exception caught in JavaScript



Throw In Javascript






throw [Exception_Message];




Picture showing the cycle of throw keyword in exception handling in JavaScript




try {
    alert('Before Throw');
    throw 'Error';
    alert('After Throw');
} catch (e) {
    alert(e);
}

Try It




Posted By  -  Karan Gupta
 
Posted On  -  Thursday, July 19, 2012

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250