#1 Printing usage after catching exception

open
nobody
None
5
2013-02-26
2013-02-26
Timo Oster
No

Hi and thank you for providing this very useful library.

I'm wondering if and how it is possible to print the usage message after catching an exception. Ideally I want to be able to print the short usage message after catching a ArgException so the user doesn't only know where something went wrong, but also how to do it right. Currently, when I call cmd.getOutput()->usage(cmd) in a catch block, a segmentation fault is the result. Probably because the CmdLine object "cmd" is no longer valid.

Regards

Timo

Discussion

  • Timo Oster
    Timo Oster
    2013-02-26

    I just realized that the library does this automatically when the CmdLine object is set to handle exceptions.

    However, if I want to handle exceptions myself, and call cmd.setExceptionHandling(false), the usage message is not automatically printed, so my question remains valid.