From e4e99aa7891fca96deeef5c6496103bed6a50dbc Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Fri, 18 Apr 2025 19:11:17 +0200 Subject: [PATCH] Main: output exception stream directly to stdout printf is used to output formated stringstream. Not only introductory information is somewhat repeated, but text can be sent directly to standard output. --- src/Main/MainCmd.cpp | 32 ++++++++++++++------------------ src/Main/MainPy.cpp | 10 ++++------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Main/MainCmd.cpp b/src/Main/MainCmd.cpp index 515d726845..4f75e013b6 100644 --- a/src/Main/MainCmd.cpp +++ b/src/Main/MainCmd.cpp @@ -36,8 +36,7 @@ #endif // HAVE_CONFIG_H #include -#include - +#include #include // FreeCAD Base header @@ -109,31 +108,28 @@ int main(int argc, char** argv) } catch (const Base::Exception& e) { std::string appName = App::Application::Config()["ExeName"]; - std::stringstream msg; - msg << "While initializing " << appName << " the following exception occurred: '" - << e.what() << "'\n\n"; - msg << "Python is searching for its runtime files in the following directories:\n" - << Base::Interpreter().getPythonPath() << "\n\n"; - msg << "Python version information:\n" << Py_GetVersion() << "\n"; + std::cout << "While initializing " << appName << " the following exception occurred: '" + << e.what() << "'\n\n"; + std::cout << "Python is searching for its runtime files in the following directories:\n" + << Base::Interpreter().getPythonPath() << "\n\n"; + std::cout << "Python version information:\n" << Py_GetVersion() << "\n"; const char* pythonhome = getenv("PYTHONHOME"); if (pythonhome) { - msg << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'."; - msg << "\nSetting this environment variable might cause Python to fail. Please contact " - "your administrator to unset it on your system.\n\n"; + std::cout << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'."; + std::cout << "\nSetting this environment variable might cause Python to fail. " + "Please contact your administrator to unset it on your system."; } else { - msg << "\nPlease contact the application's support team for more information.\n\n"; + std::cout << "\nPlease contact the application's support team for more information."; } - - printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str()); + std::cout << std::endl; exit(100); } catch (...) { std::string appName = App::Application::Config()["ExeName"]; - std::stringstream msg; - msg << "Unknown runtime error occurred while initializing " << appName << ".\n\n"; - msg << "Please contact the application's support team for more information.\n\n"; - printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str()); + std::cout << "Unknown runtime error occurred while initializing " << appName << ".\n\n"; + std::cout << "Please contact the application's support team for more information."; + std::cout << std::endl; exit(101); } diff --git a/src/Main/MainPy.cpp b/src/Main/MainPy.cpp index a09c20f303..554af37e70 100644 --- a/src/Main/MainPy.cpp +++ b/src/Main/MainPy.cpp @@ -45,7 +45,6 @@ #endif // HAVE_CONFIG_H #include -#include #include #include @@ -176,11 +175,10 @@ PyMOD_INIT_FUNC(FreeCAD) } catch (const Base::Exception& e) { std::string appName = App::Application::Config()["ExeName"]; - std::stringstream msg; - msg << "While initializing " << appName << " the following exception occurred: '" - << e.what() << "'\n\n"; - msg << "\nPlease contact the application's support team for more information.\n\n"; - printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str()); + std::cout << "While initializing " << appName << " the following exception occurred: '" + << e.what() << "'\n\n"; + std::cout << "Please contact the application's support team for more information." + << std::endl; } Base::EmptySequencer* seq = new Base::EmptySequencer();