Register based error-handling?

via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 6 00:30:20 PST 2014


It has been argued that exceptions are too slow in D to propagate 
regular errors and should just be used for the truly exceptional 
case. Then there should be a faster, but equally convenient 
alternative for regular errors.

In Go you "solve" the problem by returning tuples:
(returnvalue,errorcode) = function_call();

That is annoying. I'd rather see an implicit error code by having 
"return error(value)" be a builtin.


The basic idea is have a register based errno with language 
support:

1. On amd64 you designate one "caller save" SIMD register to 
error propagation.

2. Function signatures can specify if a return value:
- never provide errors
- provide errors that must be handled
- provide errors that can be ignored

3. The language checks if all mandatory errors are handled.

4. Functions called are only allowed to write non-zero values to 
the error register on return.

The language then provide constructs for dealing with errors:

// ignore error values, the compiler does not check
// errors until after func2() is executed (like opengl)

tryall {
     value = func1();
     value += func2();
}
catcherror{ … }

value = func(3);
if error { print_error(error); }
// error is cleared here by the compiler

value = func_optional_error();

// error is cleared here before calling a function
// that returns an error

value = func4();





























More information about the Digitalmars-d mailing list