aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-09-11 13:23:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-02 16:07:33 +0200
commitc860d1399b4ff5f3a5b1b2630bc33112c88c13e8 (patch)
tree3e6cdd7b209cc343dd791827d07bb69a700e7043 /tools
parentc1d66eec1dbaf9034e03e3efa0403a774c764373 (diff)
Change exception handling API
This patch changes the exception handling API in the engine slightly, encapsulating any use of direct throw statements and catch blocks with concrete types. In the future we need to be able to change the way these are implemented, in order to ensure that the correct stack unwinding code is triggered for throw and re-throw. This patch separates the C++ exception object thrown from the V4 exception (that includes value, throwing context pointer) and stores the latter inside the engine. In order for that to compile, ExecutionEngine::StackTrace and StackFrame had to move into the QV4 namespace directly. In addition the syntax for catching exceptions changes from try { ... } catch (QV4::Exception &ex) { ex.accept(context); QV4::ScopedValue exceptionValue(scope, ex.value()); } to try { ... } catch (...) { QV4::ScopedValue exception(scope, context->catchException()); } Context::catchException() checks if there's a "current" exception in the engine, and if not assumes that we caught an unrelated exception and consequently re-throws. partiallyUnwind() is also gone and replaced with rethrowException(), in order to encapsulate the re-throw. Lastly, in the future nesting try/catch blocks isn't going to be possible due to limitations in the common C++ ABI with regards to foreign exceptions. Change-Id: Ic81c75b057a2147e3176d8e0b4d326c14278b47d Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/v4/main.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/tools/v4/main.cpp b/tools/v4/main.cpp
index 38329b8289..3d79e8990f 100644
--- a/tools/v4/main.cpp
+++ b/tools/v4/main.cpp
@@ -113,10 +113,10 @@ DEFINE_MANAGED_VTABLE(GC);
} // builtins
-static void showException(QV4::ExecutionContext *ctx, const QV4::Exception &exception)
+static void showException(QV4::ExecutionContext *ctx, const QV4::ValueRef exception, const QV4::StackTrace &trace)
{
QV4::Scope scope(ctx);
- QV4::ScopedValue ex(scope, exception.value());
+ QV4::ScopedValue ex(scope, *exception);
QV4::ErrorObject *e = ex->asErrorObject();
if (!e) {
std::cerr << "Uncaught exception: " << qPrintable(ex->toString(ctx)->toQString()) << std::endl;
@@ -126,7 +126,7 @@ static void showException(QV4::ExecutionContext *ctx, const QV4::Exception &exce
std::cerr << "Uncaught exception: " << qPrintable(message->toQStringNoThrow()) << std::endl;
}
- foreach (const QV4::ExecutionEngine::StackFrame &frame, exception.stackTrace()) {
+ foreach (const QV4::StackFrame &frame, trace) {
std::cerr << " at " << qPrintable(frame.function) << " (" << qPrintable(frame.source);
if (frame.line >= 0)
std::cerr << ":" << frame.line;
@@ -212,9 +212,10 @@ int main(int argc, char *argv[])
if (! qgetenv("SHOW_EXIT_VALUE").isEmpty())
std::cout << "exit value: " << qPrintable(result->toString(ctx)->toQString()) << std::endl;
}
- } catch (QV4::Exception& ex) {
- ex.accept(ctx);
- showException(ctx, ex);
+ } catch (...) {
+ QV4::StackTrace trace;
+ QV4::ScopedValue ex(scope, ctx->catchException(&trace));
+ showException(ctx, ex, trace);
return EXIT_FAILURE;
}