Undo display of errors in the console

3

Is there any way to block the display of errors on the console? type Javascript errors or something like this?

    
asked by anonymous 19.03.2015 / 16:19

2 answers

7

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>
    
19.03.2015 / 16:41
4

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.

    
19.03.2015 / 16:52