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

IA2: When using ToString, print instead of throw errors #226

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spectranaut
Copy link
Contributor

See #213

When dumping the tree via a dump tree script, we should keep going even if we encounter an error

@spectranaut
Copy link
Contributor Author

@alice, this is in draft because I can't decide if this utility function I added just makes it more illegible and I should just try and catch every time I call an API function...?

@@ -21,3 +23,16 @@ inline std::string StringVectorToString(std::vector<std::string> strings) {
result = result.substr(0, pos + 1);
return result;
}

template <typename Func>
std::string exceptionToString(Func func) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: since this is internal to the library, it should be using snake_case.

That said, though, I think I agree with your qualms about this util function. It might be easier to have this take the exception and format a string (i.e. basically just do what line 33 is doing here), and then the calling code would be more like

std::string actions;

try {
  long count = this->nActions();
  for (int i = 0; i < count; ++i) {
    std::string name = this->getName(i);
    actions += " " + name;
  }
} catch (const std::exception& e)
  actions = exception_to_string(e)
}

return "Actions:" + actions;

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.

None yet

2 participants