From 20add003b16bdbaba279ef6286a0f0025658d1e2 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 25 Jun 2016 05:51:26 +0300 Subject: improve command line parsing errors --- test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index 0341bf3..a9bf401 100644 --- a/test.py +++ b/test.py @@ -22,9 +22,12 @@ def test(algorithm, input_kind=_DEFAULT_INPUT_KIND, length=_DEFAULT_LENGTH): print(output) def _parse_natural_number(s): - n = int(s) + try: + n = int(s) + except ValueError: + raise argparse.ArgumentTypeError('must be a non-negative integer: ' + str(s)) if n < 0: - raise argparse.ArgumentTypeError('must not be a negative number') + raise argparse.ArgumentTypeError('must be a non-negative integer') return n def _parse_input_kind(s): -- cgit v1.2.3