diff options
-rw-r--r-- | different_ways_of_making_errors.html | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/different_ways_of_making_errors.html b/different_ways_of_making_errors.html index c4b9d3f..05227c8 100644 --- a/different_ways_of_making_errors.html +++ b/different_ways_of_making_errors.html @@ -66,6 +66,8 @@ $ if ls real_file; then real_file True branch with 0 </pre> +<p>Extreme example of throwing raw error codes at end-users is Windows and its API. I'd encourage you to avoid going to +such lengths. <h3>Returning Error Objects</h3> <p>But you don't need to use numbers necessarily. The only requirement is that you remember about the ability to @@ -144,10 +146,10 @@ pointer constants forcing compiler and platform implementations into guaranteein real object and hopefully cause some segmentation faults here and there. <h3>Returning Wrapped Values</h3> -<p>Instead of bundling error with the value like Go did, you can wrap the value with an object that will optionally -indicate an error. This method is a simplified approach taken from functional programming languages that make heavy use -of monads. They are quite similar with main difference being flow of the error handling. The wrapper can be tailored for -errors or things like <b>Either</b> from Haskell or <b>std::variant</b> from C++ can be used. +<p>Instead of bundling error with the value in tuple or some other container like Go did, you can wrap the value with an +object that will optionally indicate the error. This method may vary from simplified wrapper to a full-pledged monad. +Depending on where you end up on this spectrum the main difference will be the flow of error handling. You can use +tailored wrappers or something more generic like <b>Either</b> from Haskell or <b>std::variant</b> from C++. <p>A naive interface of tailored wrapper could look like this: <pre> template<typename T, typename E=const char*> |