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

[Feature Request]: Roll custom exceptions over std::runtime_error #3073

Open
5 tasks done
swagtoy opened this issue Oct 9, 2024 · 3 comments
Open
5 tasks done

[Feature Request]: Roll custom exceptions over std::runtime_error #3073

swagtoy opened this issue Oct 9, 2024 · 3 comments

Comments

@swagtoy
Copy link
Contributor

swagtoy commented Oct 9, 2024

Feature Details

Right now a lot of code is burdened with std::runtime_error (std is implied in text from now on, just like what the rest of C++ contracts), which sounds nice in quick issues, but could definitely be improved and will allow for generating cleaner crash reports and MUCH better catching. Even if it's to_string'd at the end of the day, it is generally good practice to roll/extend runtime_error which allows for catching specific errors and handling them as such. Catching all errors is not considered a good practice, nor is runtime_error in the long run.

Also willing to tackle this. Take the tilemap.cpp code which i just so happened to be skimming over, we have throw std::runtime_error("Wrong tilecount count.");, but other than catching in an appropriate manner, how do we know the "category" of the error being caught, and how do we just catch errors with tilemap objects?

Feature Purpose

afasdasd

Concept Screenshots

No response

Guidelines For Reporting Issues

  • I have read https://github.com/SuperTux/supertux/blob/master/CONTRIBUTING.md#bug-reports.
  • I have verified this isn't a request that's already been submitted as an issue.
  • I have verified this isn't a discussion, or an issue with the game, but rather an actual feature request - a currently non-existent, but desired feature.
  • In this request, I have only included details about one (1) desired feature.
  • If I make a mistake while submitting this request, I agree to use the "Edit" feature to correct it, instead of closing this issue and opening a new one.
@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 9, 2024

actually this is a probably a bug report but I dont care really

@tobbi
Copy link
Member

tobbi commented Oct 9, 2024

I agree that having separate exception types / classes that extend std::exception and then catching those specifically makes a lot more sense than just catching runtime errors, especially because that way we could "swallow" actual errors that are caused by bugs. Feel free to work on it!

@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 9, 2024

Yeah. Generally speaking though, something i think i noticed is that you need to use exceptions for what they are. Exceptions. If a function has a chance of not returning a specific type or whatever, it would sometimes just return an exception instead of std::optional or a union/std::variant of some sort.

Especially more so for games, use exceptions very sparesely. Some gamedevs are EXTREMELY strict on Exceptions and have policies to only use them for low-level implementation details. For handling game "errors", this is honestly not how they should be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@tobbi @swagtoy and others