#include #include #include class MyObject : public QObject { Q_OBJECT public: MyObject(QObject *parent = 0) : QObject(parent) {} public slots: void throwError() { throw std::runtime_error("Already X"); } }; #include "main.moc" int main(int argc, char **argv) { QCoreApplication ca(argc, argv); QScriptEngine scriptEngine; MyObject *o = new MyObject; QScriptValue obj = scriptEngine.newQObject(o); scriptEngine.globalObject().setProperty("obj", obj); try { QScriptValue ret = scriptEngine.evaluate("obj.throwError()"); if (scriptEngine.hasUncaughtException()) { qDebug() << QString("Error eval script %2").arg(scriptEngine.uncaughtException().toString()); return -1; } else return -2; } catch(...) { qDebug() << "Exception eval"; return 1; } return 0; }