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

Proper error handling with subclass inherits std::runtime_error #7

Closed
vxcall opened this issue Nov 9, 2023 · 0 comments
Closed

Proper error handling with subclass inherits std::runtime_error #7

vxcall opened this issue Nov 9, 2023 · 0 comments

Comments

@vxcall
Copy link
Owner

vxcall commented Nov 9, 2023

by inheriting std::runtime_error, you can use message when you throw one.
Additionally you also gain polymorphic advantage which you can pass your custom error class to the function which takes param as std::runtime_error or std::exception.
Moreover, it has what function at the first state and it's guaranteed to not throw additional error from it.

class kur_error : public std::runtime_error {
public:
    kur_error(const std::string& message)
        : std::runtime_error(message) {
    }
};
@vxcall vxcall closed this as completed Nov 9, 2023
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

1 participant