3 ms·
I don't think that cause() being recursive is an issue, but I'm not sure why you'd want the cause if you can't do anything useful like attempt to downcast it.
by mercurial 12y ago
I don't think that cause() being recursive is an issue, but I'm not sure why you'd want the cause if you can't do anything useful like attempt to downcast it.
- comex 12y agoYou don't need to use cause(). For the LibError example, I think you'd instead want to pattern match against the actual variants defined in the enum, one of which is IoError(io::IoError), at which point you could match the IoError's kind against FileNotFound. This way you're depending on the published contract of the libraries in question, rather than the fact that you'll be given an error whose eventual cause is some file somewhere not being found, which is more of an implementation detail.
- mercurial 12y agoThat's a good idea in general, but there are times where you do need downcasting. Maybe your generic DB framework can throw a specific error on MySQL that you known how to recover from, but which is only available from cause() but not from the library's contract.
- masklinn 12y ago> but I'm not sure why you'd want the cause if you can't do anything useful like attempt to downcast it. description() and detail() are available, so it lets you display a traceback of sorts and do basic root-cause analysis.