QJSEngine: Throw exceptions from OQbject's method that is called from script, and catch this exception in C++
-
I have code like this:
try { QJSValue returned = func.callWithInstance( val_this, QJSValueList() << arg1 << arg2 ); /* ... */ } catch (std::invalid_argument e){ /* ... */ }
The
func
script calls QObject's method, and in this method exception is thrown, just like this:throw std::invalid_argument("test");
So, I was expecting that I will catch this exception in C++ code. However, application is just terminated:
terminate called after throwing an instance of 'std::invalid_argument' what(): test
Here is the relevant part of call stack:
0 __kernel_vsyscall 0xb7fdd424 1 raise 0xb6513607 2 abort 0xb6516a33 3 __gnu_cxx::__verbose_terminate_handler() 0xb66fd595 4 ?? 0xb66fb1f3 5 std::terminate() 0xb66fb22f 6 __cxa_throw 0xb66fb496 7 HTCore::ByteArrReadWrite::ensureSize bytearr_read_write.cpp 61 0x80616cb 8 HTCore::ByteArrReadWrite::putU16 bytearr_read_write.cpp 95 0x80618fa 9 HTCore::ByteArrReadWrite::qt_static_metacall moc_bytearr_read_write.cpp 103 0x8078bc8 10 HTCore::ByteArrReadWrite::qt_metacall moc_bytearr_read_write.cpp 143 0x8078e82 11 QMetaObject::metacall(QObject *, QMetaObject::Call, int, void * *) 0xb6a2aec2 12 ?? 0xb6f767f2 13 ?? 0xb6ef2c20 14 ?? 0xb6ef3bd6 15 QV4::QObjectMethod::callInternal(QV4::CallData *) 0xb6ef45ae 16 QV4::QObjectMethod::call(QV4::Managed *, QV4::CallData *) 0xb6ef4dac 17 QV4::Runtime::callProperty(QV4::ExecutionEngine *, int, QV4::CallData *) 0xb6f091a3 18 ?? 0xb0e08883 19 ?? 0xb6ea691d 20 QJSValue::callWithInstance(QJSValue const&, QList<QJSValue> const&) 0xb6e049c5 21 HTCore::ReqHandler::handle htreqhandler.cpp 129 0x805e2a6 ......
The exception is actually thrown in
HTCore::ByteArrReadWrite::ensureSize
, and after this, I expected stack to unwind toHTCore::ReqHandler::handle
, from whichcallWithInstance
was called.
Why this doesn't work?