February 12, 2013 [phobos] Exceptions in Phobos | ||||
---|---|---|---|---|
| ||||
Hi, Some time last year, I noticed there was at least one huge discussion about exceptions, and about how Phobos' exception hierarchy should be structured. Did that discussion lead to any conclusions, or any kind of consensus? (Please don't make me read through hundreds of old forum messages; I'm just looking for a quick summary.) The reason I'm asking is that I'm putting the final polish on the new std.process(*), and I need to decide whether each function should simply throw Exception on failure, or whether some of them should throw more specialised exceptions. Lars (*) Yes, I know, I've said this before. But it's for real this time; look, all tests are green: http://d.puremagic.com/test-results/pull-history.ghtml?projectid=1&repoid=3&pullid=1100 :) _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
February 11, 2013 Re: [phobos] Exceptions in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars Tandle Kyllingstad | On Tuesday, February 12, 2013 07:46:47 Lars Tandle Kyllingstad wrote: > Hi, > > Some time last year, I noticed there was at least one huge discussion about exceptions, and about how Phobos' exception hierarchy should be structured. Did that discussion lead to any conclusions, or any kind of consensus? (Please don't make me read through hundreds of old forum messages; I'm just looking for a quick summary.) > > The reason I'm asking is that I'm putting the final polish on the new std.process(*), and I need to decide whether each function should simply throw Exception on failure, or whether some of them should throw more specialised exceptions. I think that it was agreed upon that we should have a more organized hierarchy than we do, but I don't believe that the specifics were ever agreed upon (and certainly, nothing has come of it yet; I suppose that I should put it on my todo list - I'd forgotten about it). There were also some ideas about putting a Variant[] in Exception in order to be able to add more stuff which was specific to a program to any exception. As for std.process, the main question is whether anyone would want to catch and act on specific errors from std.process. If so, there there should be exception types specific to those errors. If it's generally the case that only one exception is going to be thrown per function, and you won't need to distinguish, then a single exception type is probably enough. Regardless, I think that throwing Exception is generally a bad idea. It's too generic to be useful beyond knowing that "something went wrong." And it could be the case that std.process ended up throwing something like a UTFException when processing a string that it was given (or even some other exception type that you couldn't know about if it operates on ranges or other user-defined types). If all it did was throw Exception, then you wouldn't be able to distinguish between that and something going wrong with the actual operation that was being attempted. So, unless there's another exception type in Phobos that would make a lot of sense for std.process to throw (and I can't think of one), then std.process should declare its own exception type, and whether it should have multiple exception types depends entirely on whether it has errors which may need to be distinguished from one another when catching them. And I can't answer that, because I don't know what the error conditions that it has are. - Jonathan M Davis _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
Copyright © 1999-2021 by the D Language Foundation