Opened 10 years ago

Closed 10 years ago

#3234 closed defect (fixed)

OMEdit needs to catch the exception thrown in the OpenModelicaScriptingAPIQt.cpp

Reported by: Rüdiger Franke Owned by: Adeel Asghar
Priority: high Milestone: 1.9.3
Component: OMEdit Version: trunk
Keywords: Cc:

Description (last modified by Adrian Pop)

OpenModelicaScriptingAPIQt.cpp will throw an std::runtime_error if an API command given to the omc dll will fail.
OMEdit will need to catch this, otherwise it will exit.
This doesn't happen only for FMUs, i guess it happens for any API that fails.

Either we fix this in OMEdit or in the OpenModelicaScriptingAPIQt.cpp

Change History (16)

comment:1 by Adeel Asghar, 10 years ago

Cc: Marcus Walther Volker Waurich Niklas Worschech added
setCommandLineOptions("+simCodeTarget=Cpp");getErrorString();
loadString("model M end M;");
translateModelFMU(M); getErrorString();

comment:2 by Adeel Asghar, 10 years ago

OMEdit is crashing because OpenModelicaCompiler.dll is crashing. No idea what's wrong. May be we should first fix #3232 so atleast we get it running via script.

comment:3 by Adeel Asghar, 10 years ago

gdb says

terminate called after throwing an instance of 'std::runtime_error'
  what():  translateModelFMU failed
[Inferior 1 (process 8700) exited with code 03]

comment:4 by Martin Sjölund, 10 years ago

C++ stuff used in our pretty C-based compiler? Nooooo :(

comment:5 by Adrian Pop, 10 years ago

Martin, the error that Adeel posted is from OMEdit so it does have C++ :)
Trying from omc you get a compilation error.

comment:6 by Adrian Pop, 10 years ago

The proper stack trace when running gdb on OMEdit is (after catch throw in gdb):

#0  __cxxabiv1::__cxa_throw (obj=0x1074f248, tinfo=0x921a74, dest=0x790948 <std::runtime_error::~runtime_error()>) at ../../../../gcc-4.4.0/libstdc++-v3/libsupc++/eh_throw.cc:63
#1  0x0042dc33 in OMCInterface::translateModelFMU (this=0x38d2788, className=..., version=..., fmuType=..., fileNamePrefix=...) at ../../build/include/omc/scripting-API/OpenModelicaScriptingAPIQt.cpp:2218
#2  0x00483434 in OMCProxy::translateModelFMU (this=0x3892e18, className=..., version=2, fileNamePrefix=...) at OMC/OMCProxy.cpp:1923
#3  0x004182f5 in MainWindow::exportModelFMU (this=0x28fab8, pLibraryTreeNode=0xddb9fc0) at MainWindow.cpp:847
#4  0x0041872e in MainWindow::exportModelFMU (this=0x28fab8) at MainWindow.cpp:1459
#5  0x6a2dbe2f in ZN11QMetaObject8activateEP7QObjectPKS_iPPv () from f:\openmodelica1.9.2-r25117\bin\QtCore4.dll
#6  0x651098bc in ZN7QAction9triggeredEb () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#7  0x6510b2c4 in ZN7QAction8activateENS_11ActionEventE () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#8  0x654e2cce in ZNK5QMenu4iconEv () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#9  0x654e84a8 in ZN5QMenu10timerEventEP11QTimerEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#10 0x654e8f2a in ZN5QMenu17mouseReleaseEventEP11QMouseEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#11 0x65159507 in ZN7QWidget5eventEP6QEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#12 0x654ea61c in ZN5QMenu5eventEP6QEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#13 0x6510fad0 in ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#14 0x65118dec in ZN12QApplication6notifyEP7QObjectP6QEvent () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#15 0x6a2c9cb0 in ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent () from f:\openmodelica1.9.2-r25117\bin\QtCore4.dll
#16 0x65113597 in ZN19QApplicationPrivate14sendMouseEventEP7QWidgetP11QMouseEventS1_S1_PS1_R8QPointerIS0_Eb () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#17 0x65175cc3 in ZN12QApplication8winFocusEP7QWidgetb () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#18 0x6517a09f in ZN19QApplicationPrivate27initializeWidgetPaletteHashEv () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#19 0x759462fa in USER32!OffsetRect () from C:\Windows\syswow64\user32.dll
#20 0x759480a9 in USER32!CreateWindowStationW () from C:\Windows\syswow64\user32.dll
#21 0x00030000 in ?? ()
#22 0x75946d3a in USER32!IsWindow () from C:\Windows\syswow64\user32.dll
#23 0x6517973c in ZN19QApplicationPrivate27initializeWidgetPaletteHashEv () from f:\openmodelica1.9.2-r25117\bin\QtGui4.dll
#24 0x759477c4 in USER32!AnyPopup () from C:\Windows\syswow64\user32.dll
#25 0x00000000 in ?? ()

The throw seems to originate in the OpenModelicaScriptingAPIQt.cpp and is not caught.

comment:7 by Adrian Pop, 10 years ago

We do:

MMC_CATCH_TOP(throw std::runtime_error("translateModelFMU failed");)

at that line in the OpenModelicaScriptingAPIQt.cpp code.
So I guess OMEdit needs to wrap these API calls into try catch so that it can catch the throw and display an error.

comment:8 by Martin Sjölund, 10 years ago

Hmmm... Possibly also making it a runtime_exception instead? :)

Version 0, edited 10 years ago by Martin Sjölund (next)

comment:9 by Adrian Pop, 10 years ago

Yeah, might be a good idea to make the API return a structure with the result and a status value always. But try/catch on the API call should also work rather fine and it might be more natural for C++ Qt environment.

in reply to:  7 comment:10 by Adeel Asghar, 10 years ago

Replying to adrpo:

We do:

MMC_CATCH_TOP(throw std::runtime_error("translateModelFMU failed");)

at that line in the OpenModelicaScriptingAPIQt.cpp code.
So I guess OMEdit needs to wrap these API calls into try catch so that it can catch the throw and display an error.

True. But this will just handle the exception. It doesn't fix the problem. However, i prefer doing handling in scriptingAPI as it is automatically generated.

comment:11 by Martin Sjölund, 10 years ago

Well. The failure here is CevalScript returning an empty result.
That is, https://build.openmodelica.org/Documentation/OpenModelica.Scripting.translateModelFMU.html fails instead of returning something. This is quite bad if you are using translateModelFMU anywhere in a mos-script since the script will stop if it fails an assignment. If buildModel fails, it returns empty strings.

comment:12 by Adrian Pop, 10 years ago

Cc: Marcus Walther Volker Waurich Niklas Worschech removed
Description: modified (diff)
Summary: OMEdit hangs if exporting an FMU with option +simCodeTarget=CppOMEdit needs to catch the exception thrown in the OpenModelicaScriptingAPIQt.cpp

comment:13 by Adeel Asghar, 10 years ago

r25170 handles the exception thrown by OpenModelicaScriptingAPIQt.cpp for translateModelFMU.
Why don't we get compilation fail message as we get via script on command line?

comment:14 by Adrian Pop, 10 years ago

I guess you need to call getErrorString() for that if it fails.

in reply to:  14 comment:15 by Adeel Asghar, 10 years ago

Replying to adrpo:

I guess you need to call getErrorString() for that if it fails.

Fixed in r25172.
However, we need to do exception handling for all APIs so I am keeping this ticket open.

comment:16 by Adeel Asghar, 10 years ago

Resolution: fixed
Status: newclosed

Fixed in r25179.

Note: See TracTickets for help on using tickets.