Created
November 4, 2013 18:43
-
-
Save bjouhier/7307287 to your computer and use it in GitHub Desktop.
exception broken in osx addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"targets": [ | |
{ | |
"conditions": [ | |
["OS=='mac'", { | |
"xcode_settings": { | |
"GCC_ENABLE_CPP_EXCEPTIONS": "YES" | |
} | |
}], | |
], | |
"target_name": "hello", | |
"sources": [ "hello.cc" ] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <v8.h> | |
#include <stdexcept> | |
using namespace v8; | |
void fooBar(const Arguments& args) { | |
Local<Array> loc = Local<Array>::Cast(args[0]); | |
for (uint32_t i = 0; i < loc->Length(); i++) { | |
printf("%d\n", i); | |
throw std::invalid_argument("foo"); | |
} | |
} | |
Handle<Value> Method(const Arguments& args) { | |
HandleScope scope; | |
try { | |
fooBar(args); | |
return scope.Close(String::New("world")); | |
} catch (const std::invalid_argument& ex) { | |
return scope.Close(String::New(ex.what())); | |
} | |
} | |
void init(Handle<Object> exports) { | |
exports->Set(String::NewSymbol("hello"), | |
FunctionTemplate::New(Method)->GetFunction()); | |
} | |
NODE_MODULE(hello, init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addon = require('./build/Release/hello'); | |
console.log(addon.hello(["abc", "def"])); // 'world' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile it:
Run it:
$ node hello 0 terminate called after throwing an instance of 'std::invalid_argument' Abort trap: 6
But it works if the
throw
is moved outside of the loop.Versions: