@@ -31,8 +31,8 @@ MIDI2LR. If not, see <http://www.gnu.org/licenses/>.
3131// https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values
3232namespace {
3333#pragma warning(suppress : 26426)
34- std::unordered_map<int , std::string> keyboard_names{{ 0x0000041c , " Albanian " },
35- {0x00000401 , " Arabic (101)" }, {0x00010401 , " Arabic (102)" },
34+ static const std::unordered_map<unsigned long int , std::string> keyboard_names{
35+ {0x0000041c , " Albanian " }, { 0x00000401 , " Arabic (101)" }, {0x00010401 , " Arabic (102)" },
3636 {0x00020401 , " Arabic (102) AZERTY" }, {0x0000042b , " Armenian Eastern" },
3737 {0x0002042b , " Armenian Phonetic" }, {0x0003042b , " Armenian Typewriter" },
3838 {0x0001042b , " Armenian Western" }, {0x0000044d , " Assamese - Inscript" },
@@ -128,31 +128,60 @@ std::string rsj::GetKeyboardLayout()
128128 static_assert (sizeof (CHAR) == sizeof (char ), " Windows CHAR and char different sizes." );
129129 std::array<CHAR, KL_NAMELENGTH> klid_ascii{};
130130 if (GetKeyboardLayoutNameA (klid_ascii.data ())) {
131- size_t pos{0 };
132- const auto klid{std::stoi (std::string (klid_ascii.data ()), &pos, 16 )};
133- if (const auto f = keyboard_names.find (klid); f != keyboard_names.end ())
134- return f->second ;
135- return " KLID 0x" s + klid_ascii.data () + " not found in list of names" s;
131+ try {
132+ size_t pos{0 };
133+ const auto klid{std::stoul (std::string (klid_ascii.data ()), &pos, 16 )};
134+ if (const auto f = keyboard_names.find (klid); f != keyboard_names.end ())
135+ return f->second ;
136+ return " KLID not in keyboard_names: 0x" s + klid_ascii.data ();
137+ }
138+ catch (...) {
139+ return " Exception when finding KLID name. KLID: 0x" s + klid_ascii.data ();
140+ }
136141 }
137- return " unable to get KLID" s;
142+ return " Unable to get KLID. Error " s + std::to_string ( GetLastError ()) + " . " s;
138143}
139144#endif
140145
141146DebugInfo::DebugInfo () noexcept
142147{
143- using namespace std ::string_literals;
144- info_.emplace_back (" System language " s + juce::SystemStats::getDisplayLanguage ().toStdString ());
145- info_.emplace_back (" Version " s + ProjectInfo::versionString);
146- info_.emplace_back (" App path " s
147- + juce::File::getSpecialLocation (juce::File::currentApplicationFile)
148- .getFullPathName ()
149- .toStdString ());
150- info_.emplace_back (" Keyboard type " s + rsj::GetKeyboardLayout ());
148+ try {
149+ using namespace std ::string_literals;
150+ info_.emplace_back (
151+ " System language " s + juce::SystemStats::getDisplayLanguage ().toStdString ());
152+ info_.emplace_back (" Version " s + ProjectInfo::versionString);
153+ info_.emplace_back (" App path " s
154+ + juce::File::getSpecialLocation (juce::File::currentApplicationFile)
155+ .getFullPathName ()
156+ .toStdString ());
157+ info_.emplace_back (" Keyboard type " s + rsj::GetKeyboardLayout ());
158+ }
159+ catch (...) {
160+ try {
161+ info_.emplace_back (" Failed to obtain app info. Exception." );
162+ }
163+ catch (...) {
164+ }
165+ }
151166}
167+ namespace {
168+ // placing kErrorNotice here instead of in exception handler so that handler doesn't have any
169+ // chance of throwing another exception
170+ static const std::string kErrorNotice {" Exception in GetInfo." };
171+ } // namespace
152172
153- std::string const * DebugInfo::GetInfo ()
173+ const std::string* DebugInfo::GetInfo () noexcept
154174{
155- if (iterate_ >= info_.size ())
156- return nullptr ;
157- return &info_.at (iterate_++);
175+ try {
176+ if (iterate_ >= info_.size ())
177+ return nullptr ;
178+ return &info_.at (iterate_++);
179+ }
180+ catch (...) {
181+ static auto second_time{false };
182+ if (second_time)
183+ return nullptr ;
184+ second_time = true ;
185+ return &kErrorNotice ;
186+ }
158187}
0 commit comments