Register based error-handling?

Nemanja Boric via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 6 01:36:37 PST 2014


>
> If a function named "write" fails to write, it should throw an 
> exception.  So what about functions that want to return error 
> codes instead.  What I do is prefix the function with "try".  
> You don't have to do that, but it helps me personally keep 
> track of what functions require explicit error checking.  A 
> function named "tryWrite" lets the user know the function may 
> not write and they need to check somehow whether or not it 
> failed.
>

Maybe you could consider something like returning `Result<Ok, 
Err>` (like in Rust) which will make you not forget to check for 
return code.

http://doc.rust-lang.org/std/result/



More information about the Digitalmars-d mailing list