try/catch idiom in std.datetime

Walter Bright newshound2 at digitalmars.com
Mon Nov 18 13:50:42 PST 2013


On 11/18/2013 1:23 PM, Jonathan M Davis wrote:
> Then what would you suggest for dealing with cases where a nothrow function
> calls a function which can throw in general but can't throw with the given
> arguments? Completely separate from the issue of whether std.datetime should
> need to be calling a throwing function from a nothrow function as often as it
> does, it's still an issue which must be dealt with in general. At present, any
> nothrow function which wants to call a throwing function needs to use a try-
> catch block to wrap the throwing function, and it makes good sense to use
> assert(0) to catch the case where the caller screwed up and the function can
> indeed throw. However, given that that throwing function should never throw,
> it's desirable to be able to optimize out the try-catch-assert(0). How would
> we do that without taking advantage of the fact that assert(0) indicates that
> that line of code should be unreachable?

I believe this is solving the problem in the wrong place. The function being 
called should not be throwing, and should be defined as not throwing. See my 
other posts in this thread on the topic.



More information about the Digitalmars-d mailing list