Is there any way to block the display of errors on the console? type Javascript errors or something like this?
Is there any way to block the display of errors on the console? type Javascript errors or something like this?
Use the Try block catch follows an example
<!DOCTYPE html>
<html>
<body>
<script>
try {
//veja que escrevi documentOO e o correto é document
documentOO.write('Olá Mundo');
}
catch(err) {
document.write("Ocorreu um erro: " + err.message);
}
</script>
</body>
</html>
You can reset the console and its log
method:
window.console = {
log: function(){}
};
console.log('sumiu!');
But this only affects your direct calls to console.log
. If the idea is to omit the display of errors thrown by the code, only if you treat the error as suggested by @ClevertonCarneiro. But beware of this, most of the time is the case to fix the error instead of trying to omit it.