Take a look at the function ReportException in samples/shell.cc:
void ReportException(v8::TryCatch* try_catch) {
v8::HandleScope handle_scope;
v8::String::Utf8Value exception(try_catch->Exception());
v8::Handle<v8::Message> message = try_catch->Message();
if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just
// print the exception.
printf("%s\n", *exception);
} else {
// Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptResourceName());
int linenum = message->GetLineNumber();
printf("%s:%i: %s\n", *filename, linenum, *exception);
// Print line of source code.
v8::String::Utf8Value sourceline(message->GetSourceLine());
printf("%s\n", *sourceline);
// Print wavy underline (GetUnderline is deprecated).
int start = message->GetStartColumn();
for (int i = 0; i < start; i++) {
printf(" ");
}
int end = message->GetEndColumn();
for (int i = start; i < end; i++) {
printf("^");
}
printf("\n");
v8::Handle<v8::String> stack_trace = message->GetStackTrace();
if (!stack_trace.IsEmpty()) {
v8::String::Utf8Value stack_trace_str(stack_trace);
printf("%s\n", *stack_trace_str);
}
}
}
Regards,
Søren
On Wed, Sep 10, 2008 at 9:07 PM, CGamesPlay <[EMAIL PROTECTED]>wrote:
>
> How do we use Message::GetStackTrace()? The comment says
> trace_exceptions, but that string occurs nowhere else in the library.
>
> On Sep 10, 2:54 am, Christian Plesner Hansen
> <[EMAIL PROTECTED]> wrote:
> > You can now get line numbers directly from the TryCatch; see the shell
> > sample for an example of how to use this.
> >
> > On Sep 4, 9:25 pm, "Christian Plesner Hansen"
> >
> > <[EMAIL PROTECTED]> wrote:
> > > I can't test this but as far as I can see from the code that should be
> > > a safe assumption. You may need to SetVerbose on the TryCatch for
> > > this to work properly, otherwise I think the message callback will not
> > > be called.
> >
> > > On Thu, Sep 4, 2008 at 9:11 PM, Bryan White <[EMAIL PROTECTED]>
> wrote:
> >
> > > >> Yes, you can store the Message object in a in a global variable if
> you
> > > >> hold it in a Persistent handle.
> >
> > > > That what not my concern. I was asking if it was reasonable to
> assume
> > > > in the TryCatch handler that the most recent call of the
> > > > MessageCallback was pertinent to the error.
> >
> > > > --
> > > > Bryan White
> >
>
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---