From 68cddb816d71d5413687c422b90769660e6d8888 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sat, 6 Nov 2021 16:59:04 +0000 Subject: [PATCH] Improved some assertion error messages, corresponding to Rust's unreachable!(). --- cpp/qrcodegen.cpp | 4 ++-- typescript-javascript/qrcodegen.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/qrcodegen.cpp b/cpp/qrcodegen.cpp index a5536d4..4736a40 100644 --- a/cpp/qrcodegen.cpp +++ b/cpp/qrcodegen.cpp @@ -238,7 +238,7 @@ int QrCode::getFormatBits(Ecc ecl) { case Ecc::MEDIUM : return 0; case Ecc::QUARTILE: return 3; case Ecc::HIGH : return 2; - default: throw std::logic_error("Assertion error"); + default: throw std::logic_error("Unreachable"); } } @@ -584,7 +584,7 @@ void QrCode::applyMask(int msk) { case 5: invert = x * y % 2 + x * y % 3 == 0; break; case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break; case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break; - default: throw std::logic_error("Assertion error"); + default: throw std::logic_error("Unreachable"); } modules.at(y).at(x) = modules.at(y).at(x) ^ (invert & !isFunction.at(y).at(x)); } diff --git a/typescript-javascript/qrcodegen.ts b/typescript-javascript/qrcodegen.ts index 036fc9e..bc4c31d 100644 --- a/typescript-javascript/qrcodegen.ts +++ b/typescript-javascript/qrcodegen.ts @@ -454,7 +454,7 @@ namespace qrcodegen { case 5: invert = x * y % 2 + x * y % 3 == 0; break; case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break; case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break; - default: throw "Assertion error"; + default: throw "Unreachable"; } if (!this.isFunction[y][x] && invert) this.modules[y][x] = !this.modules[y][x];