Skip to content
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

use throw to allow better control of errors #347

Open
drbergman opened this issue Jan 9, 2025 · 2 comments
Open

use throw to allow better control of errors #347

drbergman opened this issue Jan 9, 2025 · 2 comments

Comments

@drbergman
Copy link
Collaborator

We currently use exit(-1); whenever the code does something undesirable. This does not allow users to control the handling of these exceptions. We could make some simple exception classes with standardized return values that give users this control, return exception-specific return values, and make use of the try-catch block in main.cpp. Two simple exception classes would be ParsingError and SimulationError.

@davidmagnotti
Copy link

Is the idea one of the classes would look something like this?

#include <stdexcept>
#include <string>

class ParsingError : public std::runtime_error {
public:
    ParsingError(const std::string& msg) 
        : std::runtime_error(msg) {}
};

Then replace use of exit(-1) in places like here:

with something like this block:

 raise ParsingError("Error: attempted to get sbml_filename, but file was not found.");

Assuming so, that change makes sense, the code would be more maintainable.

@drbergman
Copy link
Collaborator Author

Yep, that was the kind of idea I was going for. Thanks for adding specific for it!

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

No branches or pull requests

2 participants