There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Error: User missing name
at Object.<anonymous> (/home/ccuser/workspace/error-handling-error-construction/main.js:2:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
Will logging the error stop our program from running?
The trace begins at the point of exception, only the error is arbitrarily thrown, so that is where the trace starts. The source location is given in the second line of the error message. All the rest can be ignored. They are just failing because something before has failed.
Hi there,
this exercise (url above) introduces the JavaScript Error function: “The Error function takes an argument of a string which becomes the value of the error’s message property.”
It seems pretty useful for custom errors so I tried to know more about its use by reading more material about it.
Unfortunately I’ve been unsuccessful so far in my attempts to finding anything on Google about JavaScript Error function. All links I’ve got send me to the Error Object and plenty of ways to handle errors with the try…catch statement and “new Error” syntax but nothing about the Error function.
I’ve read anything I found in MDN web docs about Javascript errors and the Error function was nowhere to be found. At least by me.
In this exercise’s example syntax “console.log(Error(‘Your password is too weak.’));”
Error doesn’t seem to behave like an Object but rather like a Function being passed a String as unique argument. It fits the above definition but I can’t find it outside Codecademy course so far.
Meanwhile this other example “console.log(new Error(‘Your password is too weak.’));”
seems to fit what I understand so far about Error. A new instance of the Error class, i.e. an Object, is created and its message property’s value is passed a String.
The lesson says that both ways will lead to the same functionality with no further explanation. It is where I get confused.
What am I getting wrong here?
Error is a class, and new is an instantiation operator that will give us an object from that class. However, we can anonymously invoke a transient object of the class using its own signature. That is because it has a constructor which is the working function when we invoke the class.
Thanks for the quick answer. I follow your logics and I reach the same conclusion. I can live with the special class thing.
Still it’s a bit tricky. I definitely need to find out more about this one.