I am having trouble with some basic error handling/catching. If I have the following code:
function test() {
areThereErrors(sum(1,2));
areThereErrors(sumo(1,2));
}
function areThereErrors(value) {
console.log(value);
}
How do I go about catching the error from the typo in the second call to areThereErrors? My basic understanding is that I have to call test() but unfortunately I only console.log 3 once and that's it. I want to be able to return true if sumo throws an error because sumo isn't a function.
NOTE: The crux of the issue is, is it possible to catch the error with code WITHIN areThereErrors?
sumowon't throw an error because it is not a function and thus never called. Instead,test()will throw the error so that's also the location in which you'd need to catch the errortryandcatch.sumowill indeed throw an error (a ReferenceError) when the attempt is made to call it.testrather than when you invokeareThereErrors(sumo(1,2))sumo(1,2)is executed before passing its returned value intoareThereErrors.