1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0030579: Draw Harness, Draw_Interpretor - catch exceptions other than Standard_Failure

This commit is contained in:
kgv 2019-03-15 13:15:18 +03:00 committed by apn
parent d9166000fe
commit f996b507d8
2 changed files with 47 additions and 36 deletions

View File

@ -112,16 +112,7 @@ namespace {
} // anonymous namespace
// MKV 29.03.05
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
static Standard_Integer CommandCmd
(ClientData theClientData, Tcl_Interp *interp,
Standard_Integer argc, const char* argv[])
#else
static Standard_Integer CommandCmd
(ClientData theClientData, Tcl_Interp *interp,
Standard_Integer argc, char* argv[])
#endif
static Standard_Integer CommandCmd (ClientData theClientData, Tcl_Interp* interp, Standard_Integer argc, const char* argv[])
{
static Standard_Integer code;
code = TCL_OK;
@ -166,18 +157,10 @@ static Standard_Integer CommandCmd
}
catch (Standard_Failure const& anException) {
// fail if Draw_ExitOnCatch is set
// MKV 29.03.05
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
const char* cc = Tcl_GetVar(interp,
"Draw_ExitOnCatch",TCL_GLOBAL_ONLY);
#else
char* const cc = Tcl_GetVar(interp,
"Draw_ExitOnCatch",TCL_GLOBAL_ONLY);
#endif
cout << "An exception was caught " << anException << endl;
if (cc && Draw::Atoi(cc)) {
std::cout << "An exception was caught " << anException << std::endl;
const char* toExitOnCatch = Tcl_GetVar (interp, "Draw_ExitOnCatch", TCL_GLOBAL_ONLY);
if (toExitOnCatch != NULL && Draw::Atoi (toExitOnCatch))
{
#ifdef _WIN32
Tcl_Exit(0);
#else
@ -191,6 +174,44 @@ static Standard_Integer CommandCmd
Tcl_SetResult(interp,(char*)(ss.str().c_str()),TCL_VOLATILE);
code = TCL_ERROR;
}
catch (std::exception const& theStdException)
{
std::cout << "An exception was caught " << theStdException.what() << " [" << typeid(theStdException).name() << "]" << std::endl;
const char* toExitOnCatch = Tcl_GetVar (interp, "Draw_ExitOnCatch", TCL_GLOBAL_ONLY);
if (toExitOnCatch != NULL && Draw::Atoi (toExitOnCatch))
{
#ifdef _WIN32
Tcl_Exit (0);
#else
Tcl_Eval (interp, "exit");
#endif
}
// get the error message
Standard_SStream ss;
ss << "** Exception ** " << theStdException.what() << " [" << typeid(theStdException).name() << "]" << ends;
Tcl_SetResult (interp, (char*)(ss.str().c_str()), TCL_VOLATILE);
code = TCL_ERROR;
}
catch (...)
{
std::cout << "UNKNOWN exception was caught " << std::endl;
const char* toExitOnCatch = Tcl_GetVar (interp, "Draw_ExitOnCatch", TCL_GLOBAL_ONLY);
if (toExitOnCatch != NULL && Draw::Atoi (toExitOnCatch))
{
#ifdef _WIN32
Tcl_Exit (0);
#else
Tcl_Eval (interp,"exit");
#endif
}
// get the error message
Standard_SStream ss;
ss << "** Exception ** UNKNOWN" << ends;
Tcl_SetResult (interp, (char* )(ss.str().c_str()), TCL_VOLATILE);
code = TCL_ERROR;
}
// log command result
if (doLog || doEcho)

View File

@ -72,26 +72,16 @@ void Draw_Window::RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB)
static void Prompt(Tcl_Interp *Interp, int partial)
{
// MKV 29.03.05
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
const char *promptCmd;
#else
char *promptCmd;
#endif
int code;
Tcl_Channel outChannel, errChannel;
outChannel = Tcl_GetStdChannel(TCL_STDOUT);
promptCmd = Tcl_GetVar(Interp,(char*)
(partial ? "tcl_prompt2" : "tcl_prompt1"), TCL_GLOBAL_ONLY);
Tcl_Channel errChannel;
Tcl_Channel outChannel = Tcl_GetStdChannel(TCL_STDOUT);
const char* promptCmd = Tcl_GetVar (Interp, partial ? "tcl_prompt2" : "tcl_prompt1", TCL_GLOBAL_ONLY);
if (promptCmd == NULL) {
defaultPrompt:
if (!partial && outChannel) {
Tcl_Write(outChannel, "% ", 2);
}
} else {
code = Tcl_Eval(Interp, promptCmd);
int code = Tcl_Eval(Interp, promptCmd);
outChannel = Tcl_GetStdChannel(TCL_STDOUT);
errChannel = Tcl_GetStdChannel(TCL_STDERR);
if (code != TCL_OK) {