Skip to content

RFC: handling of fatal errors #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

peterschrammel
Copy link
Member

Ultimate goal:

  • unify various forms of signalling fatal errors (integer error codes, booleans, exceptions of various raw types)
  • move catching of fatal errors to top-level

We've already got invariant_failedt for programming errors. I added two more (naming debatable):

  • ui_exceptiont for user input related errors
  • system_exceptiont for OS related errors

I put the top-level catch into a class derived from parse_options_baset so that the various tools do not need to duplicate the exception handling code.

This PR is for illustration of the concepts.

@hannes-steffenhagen-diffblue
Copy link
Contributor

IMHO neither system_exceptiont nor ui_exceptiont should derive from logic_error - logic errors are things like out of range access, null pointer access and the like, programmer errors we'd usually catch with invariants. Since these are meant to model things outside of our control (user input errors or OS level exceptions) they should either not derive from a std exception type at all or otherwise from runtime_error.

@NlightNFotis
Copy link
Contributor

@hannes-steffenhagen-diffblue Agreed that the exceptions in b2c6da2 should be subclassing std::runtime_error instead of logic_error.

@NlightNFotis
Copy link
Contributor

I think a large class of errors may be caught by invariants already, but maybe it could be a good idea to have an exception type that signals things gone wrong during analysis, like analysis_errort or something along these lines, for at least some of the errors I have seen in CBMC thus far could neatly fall under this category.

@@ -35,4 +36,23 @@ class parse_options_baset
bool parse_result;
};

class parse_optionst: public parse_options_baset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could remove parse_optionst and include the new code directly in parse_options_baset.

{
message.error() << e.what() << messaget::eom;
}
return 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all these exceptions are fatal and shouldn't be caught anywhere else, I wonder whether we should include the exit code in the exceptions. Then the different catch clauses would return via return e.exit_code().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that could make some sense.

@danpoe
Copy link
Contributor

danpoe commented Jun 27, 2018

I think we don't need to derive the new exception classes from any of the standard exceptions. It doesn't seem to have a benefit in this use case and only increases the chance that they get caught inadvertently. We could create a new base class fatal_exceptiont instead that defines the basic interface and then derive from that.

@peterschrammel
Copy link
Member Author

Has been done.

@peterschrammel peterschrammel deleted the feature/more-exception-types branch April 17, 2019 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants