From f996b507d8f65dd50c53bb37e56f857707eb9aaf Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 15 Mar 2019 13:15:18 +0300 Subject: [PATCH] 0030579: Draw Harness, Draw_Interpretor - catch exceptions other than Standard_Failure --- src/Draw/Draw_Interpretor.cxx | 65 +++++++++++++++++++++++------------ src/Draw/Draw_Window.cxx | 18 +++------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/Draw/Draw_Interpretor.cxx b/src/Draw/Draw_Interpretor.cxx index a5177e8de9..4fce4f4e68 100644 --- a/src/Draw/Draw_Interpretor.cxx +++ b/src/Draw/Draw_Interpretor.cxx @@ -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) diff --git a/src/Draw/Draw_Window.cxx b/src/Draw/Draw_Window.cxx index 41f779650f..55a659b700 100644 --- a/src/Draw/Draw_Window.cxx +++ b/src/Draw/Draw_Window.cxx @@ -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) {