How to avoid throwing an exceptions for a built-in function?
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 10 05:58:47 PDT 2017
On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote:
> I have a line of code that uses "to" function in std.conv for a
> purpose like:
>
> int index = to!int( user_apply[ 4 ] ); // string to int
>
> When the user_apply[ 4 ] has value, there is no problem; but
> when it is empty: ""
> it throws an ConvException exception and I want to avoid this
> exception.
>
> currently I have to use a dummy catch:
> try{
> index = to!int( user_apply[ 4 ] );
> } catch( ConvException conv_error ){
> // nothing
> }
>
> I no need to handle that, so is there any way to prevent this
> exception?
there has been talk of adding an overload that substitutes a
supplied value on failure.
apart from that there is assumeWontThrow in the stdlib somewhere.
More information about the Digitalmars-d-learn
mailing list