on error javascript code example
Example 1: js errors
JS Error Name Values:
name
Sets or returns the error name
message
Sets or returns an error message in string from
EvalError
An error has occurred in the eval() function
RangeError
A number is “out of range”
ReferenceError
An illegal reference has occurred
SyntaxError
A syntax error has occurred
TypeError
A type error has occurred
URIError
An encodeURI() error has occurred
Example 2: JavaScript Errors
<p id="demo"></p>
<script>
try {
adddlert("Welcome guest!");
}
catch(err) {
document.getElementById("demo").innerHTML = err.message;
}
</script>
Example 3: how to handle error js
// just sample try catch javascript
try {
// doing some methods
}catch (e) {
// showing message or other proses you want
console.log(e.message)
}
Example 4: on error html
<img src="logo1.jpg" onerror="this.src='error.jpg';" class="posting-logo-img">