I have been reading Rust's introduction, and the one area where I feel
pretty lost is with regard to the error handling.   Consider a simple
program like "cat" that opens, reads a file, writing it chunk-by-chunk
to standard output.  As we know, the syscalls for "open", "read", and
"write" can all fail, and my understanding is that upon encountering
such an error the entire task would abort, cleaning up resources. This
is all fine, but what if I want to provide more detailed error
messages of my own in failures for each situation?  What if numerous
fine-grained parts of the program do, in fact, have sensible recovery
options?

Relatedly, and more complicated-ly, what is Rust idiom for dealing
with cases where a high-level chunk of code wants to be able to
dictate the error handling method in a lower-level function?

I think a good example of this is given in a chapter of "Practical Common Lisp":

  
http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html

CL's flavor of "exception" handling is probably the only one I've
found gave me sufficient control comparable to rolling my own
constructs in a C program, checking everything at the lowest levels of
execution with maximum information without being as laborious.

Thanks in advance for considering my questions.

--
fdr
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to