0030579: Draw Harness, Draw_Interpretor - catch exceptions other than Standard_Failure IR-2019-03-29
authorkgv <kgv@opencascade.com>
Fri, 15 Mar 2019 10:15:18 +0000 (13:15 +0300)
committerapn <apn@opencascade.com>
Mon, 25 Mar 2019 15:24:18 +0000 (18:24 +0300)
src/Draw/Draw_Interpretor.cxx
src/Draw/Draw_Window.cxx

index a5177e8..4fce4f4 100644 (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)
index 41f7796..55a659b 100644 (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) {