Propagate exception flag
See original GitHub issueI would like to know if there is a way that I can propagate an exception instead of catch and print it?
I would expect that this can be some kwarg in the cmd2.__init__ that would allow for the exceptions to be raised instead of printed.
The use case is more for the onecmd functionality. We have a GUI that uses the some built-in commands like run_script and some other custom commands that are only implemented in the cmd2 based application. The exceptions should be caught and displayed by the GUI rather than hidden in the terminal.
Though this can be dealt with on the application level it, maybe I would not be the only one who wants this as an optional argument to be able to control the exceptions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Is it bad practice to add a flag to throw an exception?
Yeah, it's a bad idea. If the method gets into a state where it can't continue or otherwise shouldn't get into it should...
Read more >c# - Having a flag to indicate if we should throw errors
As for the flag itself, the exceptions flag is typically considered code smell because a user needs to somehow know which mode the...
Read more >Exceptions - GCC, the GNU Compiler Collection
In practice, this means propagating exceptions should not be swallowed in gratuitous catch(...) blocks. Instead, matching try and catch blocks should have ...
Read more >Exception specifications (throw, noexcept) (C++)
Exception specifications are a C++ language feature that indicate the programmer's intent about the exception types that can be propagated ...
Read more >Exceptions and Error Handling, C++ FAQ - Standard C++
How should I handle resources if my constructors may throw exceptions? ... or an array of objects) you need to check that status...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@MrKevinWeiss As you probably saw in
onecmd_plus_hooks(), cmd2 already has some custom exception handling for those it doesn’t print. As an alternative to adding a parameter to__init__(), we could add a new cmd2 exception class calledCmd2PassthroughExceptionor something similar. You could use this to wrap whatever exception you want. Ifonecmd_plus_hooks()catches an exception of this type, it will raise it instead of printing it. The question is whether cmd2 should raise the wholeCmd2PassthroughExceptionor just what’s wrapped within it.@tleonhardt @anselor What are your thoughts?
Thanks guys!