0

I have this Node.js code (Node.js version 8.5.0):

try {
    window.__karma__.complete();
}
finally { 

}       

and I am getting this error:

ReferenceError: window is not defined 

this seems pretty bizarre, considering this is in a try/catch block.

Anybody know how/why this could happen? I am on Ubuntu, I swear this does not happen on my MacOS machine. I am writing universal/isomorphic code - if window is defined, I should be in the browser.

2
  • 1
    The error isn't being caught so the runtime will still log it usually even though the flow will continue to the finally block Commented Nov 25, 2017 at 5:32
  • yeah you're probably right, pretty weird though, because I swear it wasn't happening on my MacOS machine. Commented Nov 25, 2017 at 6:27

1 Answer 1

2

As you said, this is in a try/catch block, but you missed the exception catching part.

try {
  window.__karma__.complete();
} finally {}
// -> ReferenceError: window is not defined

This works:

try {
  window.__karma__.complete();
} catch (e) {
  console.log(e)  // -> [ReferenceError: window is not defined]
} finally {}
Sign up to request clarification or add additional context in comments.

1 Comment

I think because the catch block was missing, Node.js was simply logging the error without actually throwing the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.