if (vkCreateInstance(&createInfo, null, &instance) != VK_SUCCESS) {
???
}
Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 09 What's the equivalent of std::runtime_error in D? | ||||
---|---|---|---|---|
| ||||
November 09 Re: What's the equivalent of std::runtime_error in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to alexandr3000 | On Wednesday, 9 November 2022 at 12:25:35 UTC, alexandr3000 wrote: >
The official error handling system is based on exception, e.g
manual : https://dlang.org/spec/errors.html |
November 09 Re: What's the equivalent of std::runtime_error in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to MorteFeuille123 | On Wednesday, 9 November 2022 at 13:47:09 UTC, MorteFeuille123 wrote: >On Wednesday, 9 November 2022 at 12:25:35 UTC, alexandr3000 wrote: >
The official error handling system is based on exception, e.g
manual : https://dlang.org/spec/errors.html thanks |
November 09 Re: What's the equivalent of std::runtime_error in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to MorteFeuille123 | On 11/9/22 05:47, MorteFeuille123 wrote: > class VKException : Exception > { > this(string msg) > { > super(msg); > } > } > > void _() > { > if (vkCreateInstance(&createInfo, null, &instance) != VK_SUCCESS) { > throw new VKException("cannot create VK instance") > } > } I enjoy exceptions a little differently: 1) I rarely define my own exception types because most of the time I (and the user) care only about a meaningful error message. (Having said that, during development, I sometimes print not 'exc.message' but 'exc' itself to view a stack trace even from an Exception. (I always print 'exc' for Error objects because a stack trace is almost the only thing for such programmer errors.)) 2) I never see 'throw' in my code because I think std.exception.enforce makes the code more readable (note that != is now ==): enforce(vkCreateInstance(&createInfo, null, &instance) == VK_SUCCESS, "cannot create VK instance"); 'enforce' can throw special exception types as well: enforce!VKException(/* ... */); And for all vk* functions that should return VK_SUCCESS, the whole thing can be wrapped in a function template but one needs to learn from 'enforce's implementation to ensure file and line numbers are reported as well: vkEnforce(vkCreateInstance(&createInfo, null, &instance), "cannot create VK instance"); Ali P.S. There is also the Learn forum, where such topics may be more effective. :) |
November 09 Re: What's the equivalent of std::runtime_error in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to alexandr3000 | On Wednesday, 9 November 2022 at 12:25:35 UTC, alexandr3000 wrote: >
See Ali's answer. Here's the link to enforce: And here's exception: |
Copyright © 1999-2021 by the D Language Foundation