Ask Your Question
1

CommandLineParser: How to catch invalid input to numeric parameter

asked 2016-03-11 12:01:38 -0600

Is there a way to know if a user passes invalid input to a numeric argument with CommandLineParser? e.g. if this is my command line:

./app -s=sss

then this code:

markerSize = parser.get<float>("s");

returns 0 and an error message is printed to the console. I need to know the difference between 0 and invalid input. It doesn't throw an exception so I can't use try … catch.

edit retag flag offensive close merge delete

Comments

did you setup a meaningful default value ? like:

String keys=
    "{fps            | -1.0f | fps for output video }"
    "{s              | -1.0f | marker size            }";
CommandLineParser cmd(argc,argv,keys);
berak gravatar imageberak ( 2016-03-12 01:49:06 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2016-03-11 16:41:16 -0600

Tetragramm gravatar image

Well, looking at the sample code, you call parser.check() to see if there were any errors, and then parser.printErrors() tells you what went wrong.

http://docs.opencv.org/3.1.0/d0/d2e/c...

It doesn't say if calling parser.has("s") would return false if there were errors, I suppose you'd have to check that yourself.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-11 12:01:38 -0600

Seen: 238 times

Last updated: Mar 11 '16