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

Vulkan-Hpp specific exception classes #97

Closed
RippeR37 opened this issue Apr 10, 2017 · 4 comments
Closed

Vulkan-Hpp specific exception classes #97

RippeR37 opened this issue Apr 10, 2017 · 4 comments

Comments

@RippeR37
Copy link
Contributor

RippeR37 commented Apr 10, 2017

What do you think about adding custom exception/error classes derived from one of the std::exception derived classes? Currently without special filtering developer can't really know if given exception (like std::system_error was thrown by Vulkan-Hpp or other piece of code and with that developers would be able to use natural exceptions "filtering" like:

try {
    // some Vulkan-Hpp code that can throw
    // with some normal code that can throw
} catch(const vk::error& vk_error) {
    // error from vulkan-related code
} catch(const std::exception& exception) {
    // error related to normal code / STL / etc.
}

Since exceptions already add some small overhead (mostly when fired), maybe we could also add hierarchy of exceptions representing some scenarios based on VkResult return value like

vk::error
    - vk::out_of_memory_error
        - vk::out_of_device_memory_error
        - vk::out_of_host_memory_error
    - vk::initialization_failed_error
    - vk::device_lost_error
    - ...

That way some errors might be handled right away and others might for example terminate application.
Worst case you could still catch them by std::exception or another STD-base-class.

@asuessenbach
Copy link
Contributor

I think, this is a good idea. I will introduce them in the next couple of days.

RippeR37 added a commit to RippeR37/Vulkan-Hpp that referenced this issue Apr 14, 2017
@RippeR37
Copy link
Contributor Author

I'm glad you liked it. I was thinking on how this should be implemented because standard exception classes doesn't inherit virtually, so we can't simply make:

vk::Error : std::exception
vk::SystemError : Error, std::system_error
vk::OutOfDeviceMemoryError : SystemError

and I've came up with couple ideas but none were perfect. Above implementation tries to:

  • achieve backwards compatibility with existing code (exceptions inherit from std::logic_error or std::system_error)
  • not double-inherit anything
  • allow for grouping of Vulkan-Hpp exceptions and catch only them
  • use existing STL exceptions like std::logic_error and std::system_error so that systems that work with them can be used here too
  • expose some API to get exception message in base Vulkan-Hpp exception class

It's not perfect but without virtual inheritance between STL exceptions I think we can't do better.

P.S. I haven't updated vulkan.hpp there because for some reasons rebuilding it on my system changes each line, even without any changes...

@asuessenbach
Copy link
Contributor

Regarding the changes on every line: this is probably due to a different end-of-line setting on your end. We're using CR/LF (Windows-style).

@asuessenbach
Copy link
Contributor

Resolved with pull-request #99.

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