Updated Java, C++, Python, Rust worker programs to catch the new exception; removed error message string comparisons.

This commit is contained in:
Project Nayuki 2018-10-26 02:42:35 +00:00
parent 8da8107cc2
commit c36c4a28eb
4 changed files with 5 additions and 13 deletions

View File

@ -91,11 +91,7 @@ int main() {
std::cout << (qr.getModule(x, y) ? 1 : 0) << std::endl;
}
} catch (const std::length_error &ex) {
if (strcmp(ex.what(), "Data too long") != 0) {
std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
} catch (const qrcodegen::data_too_long &ex) {
std::cout << -1 << std::endl;
}
std::cout << std::flush;

View File

@ -91,9 +91,7 @@ public final class QrCodeGeneratorWorker {
System.out.println(qr.getModule(x, y) ? 1 : 0);
}
} catch (IllegalArgumentException e) {
if (!e.getMessage().equals("Data too long"))
throw e;
} catch (DataTooLongException e) {
System.out.println(-1);
}
System.out.flush();

View File

@ -68,9 +68,7 @@ def main():
for x in range(qr.get_size()):
print(1 if qr.get_module(x, y) else 0)
except ValueError as e:
if e.args[0] != "Data too long":
raise
except qrcodegen.DataTooLongError:
print(-1)
sys.stdout.flush()

View File

@ -79,7 +79,7 @@ fn main() {
match QrCode::encode_segments_advanced(&segs, ECC_LEVELS[errcorlvl as usize],
Version::new(minversion as u8), Version::new(maxversion as u8), msk, boostecl != 0) {
Some(qr) => {
Ok(qr) => {
// Print grid of modules
println!("{}", qr.version().value());
for y in 0 .. qr.size() {
@ -88,7 +88,7 @@ fn main() {
}
}
},
None => println!("-1"),
Err(_) => println!("-1"),
}
use std::io::Write;
std::io::stdout().flush().unwrap();