Hi,

It's best demonstrated via some code:

#include <v8.h>
#include <list>
#include <iostream>
#include <string>
#include <assert.h>

using namespace std;
using namespace v8;

static std::string jsToStr(Local<Value> v, const std::string& fallback = 
"<toStr failed>") {
if(v.IsEmpty()) return fallback;
auto obj = v->ToString();
String::Utf8Value utf8(obj);
if(*utf8) return *utf8;
return fallback;
}


static Local<Value> execJsScript(const std::string& jsCode) {
Local<String> source = String::NewFromUtf8(Isolate::GetCurrent(), 
jsCode.c_str());
Local<v8::Script> script = Script::Compile(source);
assert(!script.IsEmpty());
return script->Run();
}


void test_js_ExcRethrow() {
auto isolate = Isolate::New();
Isolate::Scope isolateScope(isolate);
HandleScope handleScope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope contextScope(context);
auto globalObj = context->Global();

{
TryCatch try_catch;
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, 
"foo")));
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
}

{
TryCatch try_catch;
{
TryCatch try_catch; 
execJsScript("throw new Error('hi');");
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
try_catch.ReThrow();
}
assert(try_catch.HasCaught());
cout << jsToStr(try_catch.Exception()) << endl;
}
}


This prints:

<toStr failed>
Error: hi
<toStr failed>

But I would have expected:

Error: foo
Error: hi
Error: hi

Am I doing something wrong?

This is with V8 3.25.8.

Thanks,
Albert


-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to