how to raise error in js code example
Example 1: javascript how to raise the error
if (..condition..) {
throw 'Error message';
}
Example 2: javascript try catch
<html>
<head>Exception Handling</head>
<body>
<script>
try {
throw new Error('This is the throw keyword'); //user-defined throw statement.
}
catch (e) {
document.write(e.message); // This will generate an error message
}
</script>
</body>
</html>