Undo error display on console

Asked

Viewed 292 times

3

Is there any way you want to display errors in the console? like Javascript errors or something?

  • 4

    correcting the mistakes.

  • What would be the purpose of "hiding" the mistakes? Simply prevent a user from viewing them when loading the page or is it because it is breaking at some point in the code that makes no difference/does not want to tidy up at the moment?

  • @nmindz the two.. type I am using js for websockets and when it does not connect it shows the address of the server.. is capricho msm

  • If you really need this you’d better override the display function and return blank

2 answers

7

Use the block Try 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>

4

You can reset the console and its method log:

window.console = {
    log: function(){}
};
console.log('sumiu!');

But this only affects your direct calls to console.log. If the idea is to omit displaying errors released by the code, only if you treat the error as @Clevertoncarneiro suggested. But beware of this, most of the time it is the case to correct the error instead of trying to omit it.

  • where do you have this full function? where it performs the log correctly

  • How so, I did not understand your doubt. The console is an object provided by the browser.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.