how to throw error object in javascript code example
Example 1: javascript throw new error
throw new Error("Error message here"); // Uncaught Error: Error message here
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>