On Tue, Jan 1, 2013 at 3:45 PM,  <[email protected]> wrote:
> I have the following code:
>
>> try {
>>      require('./index.js');
>> }
>> catch(e) {
>>     console.log('----------------------');
>>     console.log(e.stack);
>> }
>
>
> When I run the code, the following gets logged to the console:
>
>> C:\[path]\index.js:9
>>         return1 response.send('asdf');
>>                 ^^^^^^^^
>> ----------------------
>> Unexpected identifier
>> SyntaxError: Unexpected identifier
>>     [Stack trace]
>
>
>
> According to the output, the first blurb of text (C:\[path] etc...) is an
> internally logged error outside the exception object, since it appears
> before the '-------------'.
> I've tried everything to catch this error so I can write it to a file or
> email it, but it seems completely uncatchable. Is there something I'm
> missing?

No, it's always printed.  require() calls `vm.runInThisContext(code,
filename, true)`.  The third (undocumented) argument tells
vm.runInThisContext() to warn on syntax errors.

The reason it works like that is that SyntaxErrors in V8 are somewhat
special; other exceptions have stack traces that you can print or
inspect, SyntaxErrors do not.  That makes it rather hard to figure out
where it originates from in deep require() trees, hence the current
approach.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to