Throw exception out of a function : Exception « Development « JavaScript Tutorial






<html>
<head>
<title>Try Catch Example</title>
<script type="text/javascript">

function addTwoNumbers(a, b) {
    throw new Error("Two numbers are required.");
}

try {
    result = addTwoNumbers(90);
} catch (oException) {
    alert(oException.message);
}

</script>
</head>
<body>
</body>
</html>








4.7.Exception
4.7.1.Syntactic exception
4.7.2.Array index to large exception
4.7.3.Get Exception message
4.7.4.Exception handler will bypass the statements
4.7.5.Get Exception name
4.7.6.Check the exception name and output exception message
4.7.7.Check Exception type with instanceof operator
4.7.8.Throw exception out of a function