Menu

#29 Document how to use ExitException to avoid program termination

1.2.x
closed-fixed
None
5
2020-12-30
2020-12-10
No

I'm using TCLAP on Debian (libtclap-dev 1.2.2-1+b1) and I use it to parse messages I send between long-running programs. Sometimes I mistype an argument name which leads to a call to exit() at the end of CmdLine::parse, killing my program. Could that function instead just throw an ExitException I can catch?

Discussion

  • Daniel Aarno

    Daniel Aarno - 2020-12-11

    Would it work to call setExceptionHandling(false) to allow the exception to propagate?

     
    • Alexander Brock

      Alexander Brock - 2020-12-11

      That works nicely for me, thank you.
      I think the manual should be updated, in the example it says "catch (TCLAP::ArgException &e) // catch any exceptions" so I got confused when my program terminated and gdb wouldn't show me any reason for that.

       
  • Daniel Aarno

    Daniel Aarno - 2020-12-11
    • assigned_to: Daniel Aarno
     
  • Daniel Aarno

    Daniel Aarno - 2020-12-11

    Yeah, this was initially added as an internal implementation detail to allow resources to be cleaned up before exiting, but it can actually be useful in cases such as you described. I think we should document it properly.

     
  • Daniel Aarno

    Daniel Aarno - 2020-12-30
    • summary: Please don't exit(), throw an exception a user may catch. --> Document how to use ExitException to avoid program termination
     
  • Daniel Aarno

    Daniel Aarno - 2020-12-30

    Documentation has been updated for both 1.2 and 1.4.

     
    👍
    1
  • Daniel Aarno

    Daniel Aarno - 2020-12-30
    • status: open --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.