1

I'm trying to force a stack overflow with this code:

// Throws stack overflow exception

var count = 0;

try {
    (function curse() {
        console.log(count++);
        curse();
    })();
} catch (e) {
    console.log('ERROR');
    console.log(e.message);
}

However, when I run it, it prints numbers to the screen and then exits gracefully. No exception thrown, I can remove the try-catch and still no exception is output to the console.

Why don't I get an exception message dumped to the console?

Node version is v0.12.2, V8 is 3.28.73.

8
  • Do you mean curse()? It's called and the integers are printed out to the screen as I'd expect. It just finishes and exits though. Commented Oct 8, 2015 at 0:18
  • It does when I run it in jsfiddle - provide more information (what is the js being run in?) Commented Oct 8, 2015 at 0:32
  • prints what to the screen, and endless stream of numbers? what node.js version? Commented Oct 8, 2015 at 0:33
  • @MaineCoder It's in the title: "Node not throwing (...)" Commented Oct 8, 2015 at 0:34
  • @MaineCoder I did put it in JSFiddle, I didn't link it as it crashes the browser so I thought it would be a bit mean. It prints out numbers, get's slow, then throws a RangeError and then just goes a bit nuts as expected. Commented Oct 8, 2015 at 0:35

1 Answer 1

1

If you upgrade to the latest node.js (currently v4.1.2), you will probably be able to see the exception message dumped to the console. This seems to have been a bug in older versions of node.js.

Also, in your current version of node.js, if you took out the console.log(count++); statement, you might have been able to see the exception message. At least, that worked for me with v0.10.26.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't know how I had such an old node. I've updated it, same result though.

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.