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

Better C++ style error support. #82

Open
CarloWood opened this issue Jul 15, 2021 · 0 comments
Open

Better C++ style error support. #82

CarloWood opened this issue Jul 15, 2021 · 0 comments

Comments

@CarloWood
Copy link
Contributor

CarloWood commented Jul 15, 2021

C++ has an Error Handling facility. This includes error categories by means of which collisions between equal integer error values can be avoided.

This means that in C++ one should use std::error_code instead of int.

I propose to allow for the user to set a call back for errors that passes a std::error_code instead of an int.
Currently it is not possible to set an error call back other than overriding what glfwpp has set (in which case
you get an int, of course; and lose the advantage of the wisdom in the current builtin errorCallback).

Aka - the user calls libary.set_error_callback([](std::error_code code, std::string what){ ... }) and is called back for runtime errors (we can leave in the asserts, although not everyone might want to use an assert :/).

I implement this for every C library that I use, it is very nice to have general error codes.
I already implemented this for glfwpp too, see my gui_ErrorCodes.cxx.

So, if you think it is a good idea I can integrate it into glfwpp for you and do a pull request.

PS The THROW_ALERTC in that code throws an exception that automatically converts the enum to a std::error_code,
when caught and printed, I get - for example -:

WARNING       : AIAlert: 
    glfw3::error_callback(65546, "Cannot make current with a window that has no OpenGL or OpenGL ES context"):
    The specified window has no context (GLFW_NO_WINDOW_CONTEXT), caught in HelloTriangleVulkanApplication.cxx.
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