On 22 September 2010 15:30, Stuart McCulloch <[email protected]> wrote:
> On 22 September 2010 14:32, Kevin Wright <[email protected]> wrote: > >> The difference becomes more apparent when your code looks like this: >> >> try { >> val handle = fileOpen(fileName) >> doSomethingWithFile(handle) >> moreFileOps(handle) >> yetSomethingElse(handle) >> . >> . >> . >> another functionUsingTheFile(handle) >> . >> . >> . >> . >> . >> keepGoing(handle) >> . >> . >> . >> . >> . >> promiseThisIsTheLastOne(handle) >> } catch { >> case Exception(e) => logError(e) >> } >> >> >> Now answer quickly: >> - where might the exception have been thrown? >> - which of those methods have side-effects? Does it matter? How do you >> determine what changes to roll-back when an exception is thrown? >> - does it matter if the file is "not found" halfway through, instead of >> when you first opened it? Would the correct response be different in these >> cases? >> > > but don't you have the same problem with Either / error codes? > > if the developer can sequentially call moreFileOps(handle), > yetSomethingElse(handle), etc. without checking the return value then they > can fall into the same trap... > That's very much the point... If a file can't be found when you're first trying to open it, then that's normal. If a file can't be found after you've already been working with it, then that's exceptional. The two cases are substantially different, and should be acted upon in different ways. When opening a file I'd expect a non-exception return that indicates if I was able to open it or not. If a file mysteriously vanishes mid-process then that's emphatically *not* normal, chances are that there's no way to recover from such a problem and the code will need to break out from several layers of stack to use a more general "something very odd has happened" error reporting mechanism - which implies an unchecked exception. -- Kevin Wright mail / gtalk / msn : [email protected] pulse / skype: kev.lee.wright twitter: @thecoda -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
