November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | On Thursday, 6 November 2014 at 20:58:02 UTC, Ola Fosheim Grøstad wrote:
> On Thursday, 6 November 2014 at 20:06:55 UTC, deadalnix wrote:
>> I don't think we should have a language construct for that. It is
>> possible to pack the returned value in a struct that enforce
>> error checking.
>
> How?
The most similar thing that I can think about is Boost Optional.
| |||
November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jeremy Powers | On Thursday, 6 November 2014 at 19:18:14 UTC, Jeremy Powers via Digitalmars-d wrote: > On Thu, Nov 6, 2014 at 1:17 AM, Jonathan Marler via > suggestion than checked exceptions though... I think the worst thing about exceptions is the syntax deformation introduced by all the try/catch blocks. Something like a "flat try/catch" could help a bit: foo(); //implicit try if declared with checked exceptions check(exception1, exception2) { writeln("1 or 2")}; check(exception3) writeln("this is 3"); //compilation error since exception4 was not checked | |||
November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan Marler | On Thursday, 6 November 2014 at 09:17:55 UTC, Jonathan Marler wrote: > On Thursday, 6 November 2014 at 08:30:22 UTC, Ola Fosheim Grøstad wrote: > I've been in your shoes before, wondering why there aren't better mechanisms for error handling. Me too, I wondered a bit about this. For C-like languages, this is the most structured mechanism that I did find: https://developer.gnome.org/glib/stable/glib-Error-Reporting.html But, in the end, we went with standard return codes. | |||
November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to eles | On Thursday, 6 November 2014 at 21:13:53 UTC, eles wrote:
> The most similar thing that I can think about is Boost Optional.
Yes, that is kind of like Rust's std::result or Haskell's Maybe, but it does not support delaying the handling like you do in OpenGL.
What is desirable is that you are allowed to continue as long as you eventually handle the error. That way you can minimize the error checking… And the mechanisms should also not introduce any cache misses…
| |||
November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | Something a little better than Boost's Optional: Expected<T> http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C | |||
November 06, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ZombineDev | On Thursday, 6 November 2014 at 21:55:42 UTC, ZombineDev wrote:
> Something a little better than Boost's Optional:
> Expected<T>
> http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C
If you have exceptions maybe, but not good enough.
And none of the Maybe-like solutions work when you don't have a return value, so they don't enforce error-handling.
| |||
November 07, 2014 Re: Register based error-handling? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | On Thursday, 6 November 2014 at 20:58:02 UTC, Ola Fosheim Grøstad
wrote:
> On Thursday, 6 November 2014 at 20:06:55 UTC, deadalnix wrote:
>> I don't think we should have a language construct for that. It is
>> possible to pack the returned value in a struct that enforce
>> error checking.
>
> How?
>
struct ErrorCodeResult(T) {
// Option 1.
inout(T) get() inout {
if (error_code) throw new Exception("Check error code you
morron !");
return result;
}
// Optin 2.
auto get(alias success, alias failure)() {
if (error_code) return failure(error_code);
return success(result);
}
immutable uint error_code;
private:
T result;
}
The option 3 is to use opDispatch to do the check on everything
and return a ErrorCodeResult of whatever should have been
returned.
Options are numerous for various safety levels, and all as fast
as the manual check.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply