title: Incorrect error throw order inside of console.log?
body: <p>The code here is an extremely simplified version of what I am actually doing so please don't try to search for any deep meaning in this. I define a custom error like this.</p>
  
  <pre><code>function CustomError(message) {
    this.message = message;
    this.stack = (new Error()).stack;
  }
  CustomError.prototype = Object.create(Error.prototype);
  </code></pre>
  
  <p>Next, I create a simple function with only one purpose and that is to throw this error.</p>
  
  <pre><code>function foo() {
    throw new CustomError('custom error message');
  }
  </code></pre>
  
  <p>Now I create a next function that will enter an infinite loop, checking for any errors, breaking as soon as any error, except for the custom one, is caught (well, it should but doesn't). </p>
  
  <pre><code>function bar() {
    for (;;) {
      try {
        console.lg(foo());
      } catch (error) {
        if (error instanceof CustomError) {
          console.log(error);
        } else {
          throw new Error(error);
        }
      }
    }
  }
  
  bar();
  </code></pre>
  
  <p>There is an intentional error in spelling of <code>console.lg(foo());</code> which should throw an error that is not an instance of <code>CustomError</code>, causing the <code>throw new Error(error);</code> line to be reached that would lead to the crash of the program. </p>
  
  <p>Instead, the <code>foo()</code> function inside of <code>console.lg(foo());</code> is executed and <code>CustomError</code> is thrown, and the loop continues forever.</p>
  
  <p>There is a chance that I am just making a silly mistake here but I don't see where. So my questions are:
  Why is the interior of <code>console.lg();</code> reached without breaking the program when it is clearly not a valid code? And why is the <code>CustomError</code> thrown prior to the 'not a valid method' error? </p>