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.
This commit is contained in:
Ladislav Michl
2025-04-18 19:11:17 +02:00
parent 2bae2a3242
commit 0276ff13f5
2 changed files with 18 additions and 24 deletions

View File

@@ -36,8 +36,7 @@
#endif // HAVE_CONFIG_H
#include <cstdio>
#include <sstream>
#include <ostream>
#include <QString>
// 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);
}

View File

@@ -45,7 +45,6 @@
#endif // HAVE_CONFIG_H
#include <cstdio>
#include <sstream>
#include <iostream>
#include <QByteArray>
@@ -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();