From 9639ce12f20adce64aeeb11f8b3fc9e4d3b8760b Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 26 Mar 2014 23:48:44 +0000 Subject: [PATCH] Exceptions caught in main() shown in message box. '\' and '/' no longer allowed in --rig git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3932 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 5f8d552a0..6e5c2cb70 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include #endif #include +#include #include #include #include @@ -28,9 +29,9 @@ QString my_key; int main(int argc, char *argv[]) { + QApplication a(argc, argv); try { - QApplication a(argc, argv); setlocale (LC_NUMERIC, "C"); // ensure number forms are in // consistent format, do this after // instantiating QApplication so @@ -49,6 +50,11 @@ int main(int argc, char *argv[]) if ('-' != temp_name[0] && !temp_name.isEmpty ()) { + if (temp_name.contains (QRegularExpression {R"([\\/])"})) + { + throw std::runtime_error (QObject::tr ("Invalid rig name - \\ & / not allowed").toLocal8Bit ().data ()); + } + a.setApplicationName (a.applicationName () + " - " + temp_name); } multiple = true; @@ -76,7 +82,7 @@ int main(int argc, char *argv[]) if(!mem_jt9.attach()) { if (!mem_jt9.create(sizeof(jt9com_))) { - QMessageBox::critical( 0, "Error", "Unable to create shared memory segment."); + QMessageBox::critical (nullptr, "Error", "Unable to create shared memory segment."); exit(1); } } @@ -111,10 +117,12 @@ int main(int argc, char *argv[]) } catch (std::exception const& e) { + QMessageBox::critical (nullptr, QObject::tr ("Error"), e.what ()); std::cerr << "Error: " << e.what () << '\n'; } catch (...) { + QMessageBox::critical (nullptr, QObject::tr ("Unexpected"), QObject::tr ("Error")); std::cerr << "Unexpected error\n"; throw; // hoping the runtime might tell us more about the exception }