I am writing a program which loads a file and run some functions on it. Multiple files can be loaded.
If there's an error loading the file, like a misspelling of the name, I log a console.error
. But I don't want to stop the execution.
Does console.error
stops the execution? Does throw new error
can be an alternative? Or should I use console.warn
?
I am writing a program which loads a file and run some functions on it. Multiple files can be loaded.
If there's an error loading the file, like a misspelling of the name, I log a console.error
. But I don't want to stop the execution.
Does console.error
stops the execution? Does throw new error
can be an alternative? Or should I use console.warn
?
- 3 Did you try it out? Make a small dummy script to see what happens? – Calvin Godfrey Commented Jun 18, 2019 at 15:45
-
console.error()
: "Outputs an error message to the Web Console" – Andreas Commented Jun 18, 2019 at 15:47 - @CalvinGodfrey Thanks for the idea! I didn't get that in mind and tried it out in the browser console! – Sanket Singh Commented Jun 18, 2019 at 15:51
- @CalvinGodfrey it's more convenient for future readers to have a SO question about this, so this question is still very valid. Plus, different browsers could behave differently, so a dummy script would not be conclusive – Joe C. Commented Apr 8, 2022 at 23:16
-
console.error
doesn't throw, butthrow
does produce (in Chrome, at least) the same red squiggles and circle-X thatconsole.error
does, producing a similar UI and perhaps Pavlovian response from developers;^D
. So if you're looking in the dev tools console, you might be forgiven for assuming something similar has happened. – ruffin Commented Dec 2, 2022 at 14:58
1 Answer
Reset to default 10Does console.error stops the execution?
No
Does throw new error can be an alternative?
Yes, as follow: throw new Error("Message");