Status: New
Owner: ----

New issue 1455 by [email protected]: Catching a termination exception
http://code.google.com/p/v8/issues/detail?id=1455

To quote from v8.h's TryCatch comments:

   * Currently, the only type of exception that can be caught by a
   * TryCatch handler and for which it does not make sense to continue
   * is termination exception.  Such exceptions are thrown when the
   * TerminateExecution methods are called to terminate a long-running
   * script.

I'm interpreting this to mean that if a TerminateExecution method is called, then the try catch handler should catch the termination exception (HasCaught() returns true) and should indicate that we can't/shouldn't continue (CanContinue() returns false).

Let us examine this behavior across various versions. The code I'm using as the example program is as follows:

#include <v8.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
  v8::TryCatch handler;

  v8::V8::TerminateExecution();

  if (handler.HasCaught()) {
    puts("TE caught");
  } else {
    puts("TE not caught");
  }

  if (handler.CanContinue()) {
    puts("Can continue");
  } else {
    puts("Can't continue");
  }

  return 0;
}

The behavior I expect is for the program to output:
TE caught
Can't continue


On 2.5.9.22, I get the following output:
TE not caught
Can continue

On 3.1.8.22, I get the following output:
TE not caught
Can continue

On 3.4.3, I get the following output:
TE caught
Can continue

Which seems to be what I'd expect, however, if I comment out the `v8::V8::TerminateExecution();` line, so that no termination exception should be thrown, I would expect to get the output of:
TE not caught
Can continue

However, on 3.4.3, I get the following output:
TE caught
Can continue

Which means that although there is no code between the TryCatch handler's declaration and the check to see if it caught anything, it believes that it caught an exception.

Using gdb to examine the state of `handler` in the case of TerminateExecution() being commented out shows:

(gdb) print handler
$1 = {isolate_ = 0x8431110, next_ = 0x0, exception_ = 0x0, message_ = 0x0, is_verbose_ = false,
  can_continue_ = true, capture_message_ = true, rethrow_ = false}
(gdb) print handler.Exception()
# Fatal error in src/runtime-profiler.h, line 50
# CHECK(has_been_globally_setup_) failed

If one reinserts the call to TerminateExecution() and adds an explicit call to `v8::V8::Initialize()` at the very beginning of the program, the behavior on 3.4.3 changes so that it now outputs:
TE not caught
Can continue

Which is similar to the previous versions, yet still not what I expect.

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to