Catching ArgumentTypeError Exception From Custom Action
What is the best practice to throw an ArgumentTypeError exception from my own custom action and let the argparse to catch it for me? It seems that argparse's try/except block does
Solution 1:
After looking at argparse source code I figured out that it translates ArgumentTypeError to ArgumentError exception.
So instead of:
raise argparse.ArgumentTypeError("Duplicate OuterIPs found")
I should have:
raise argparse.ArgumentError(self, "Duplicate OuterIPs found")
And argparse would still do the rest for me (catch exception and print usage message) ...
Post a Comment for "Catching ArgumentTypeError Exception From Custom Action"