Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 13 May 2017 at 09:51:40 UTC, k-five wrote: On Saturday, 13 May 2017 at 09:05:17 UTC, Jonathan M Davis But obviously, to know what's actually happening with your code, you're going to have to profile and benchmark it - Can you please give a link or page or something to read about

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread k-five via Digitalmars-d-learn
On Saturday, 13 May 2017 at 09:05:17 UTC, Jonathan M Davis wrote: For the most part, when parsing a string, std.conv.to's approach of just parsing the string and throwing an exception if/when it fails is the most efficient, because it's only going to parse the string once, whereas calling a

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 May 2017 at 08:50:20 UTC, k-five wrote: Way arguing when a simple code can clarify the subject? right? If am not clear so consider me as an stupid man, no problem at all. but CAN you please solve it for me? import std.stdio: writeln; import std.conv:to; void

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 12, 2017 10:42:18 H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, May 12, 2017 at 12:47:04PM +0200, ag0aep6g via Digitalmars-d-learn wrote: > > On 05/12/2017 10:32 AM, k-five wrote: > > > Interesting! I was worried about performance and for that I did not > > > want to use

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-13 Thread k-five via Digitalmars-d-learn
On Saturday, 13 May 2017 at 02:40:17 UTC, Mike B Johnson wrote: You are not making a lot of sense: 1. Exception do bubble up, so you don't need to "handle" exceptions at the call site if you don't want to. The whole point of exceptions is do effectively do what you want. 2. You say that

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread Mike B Johnson via Digitalmars-d-learn
On Thursday, 11 May 2017 at 16:07:22 UTC, k-five wrote: On Wednesday, 10 May 2017 at 21:19:21 UTC, Stanislav Blinov wrote: On Wednesday, 10 May 2017 at 15:35:24 UTC, k-five wrote: On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 12, 2017 at 12:47:04PM +0200, ag0aep6g via Digitalmars-d-learn wrote: > On 05/12/2017 10:32 AM, k-five wrote: > > Interesting! I was worried about performance and for that I did not > > want to use try-catch. > > So (isNumberic) is a good solution. > >

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread ag0aep6g via Digitalmars-d-learn
On 05/12/2017 10:32 AM, k-five wrote: Interesting! I was worried about performance and for that I did not want to use try-catch. So (isNumberic) is a good solution. http://dlang.org/phobos/std_traits.html#isNumeric If you're doing this for speed, you better be benchmarking. Exceptions are

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread k-five via Digitalmars-d-learn
On Friday, 12 May 2017 at 09:03:39 UTC, Jonathan M Davis wrote: That's the wrong isNumeric. Unfortunately, both std.string and std.traits have an isNumeric. std.traits.isNumeric is an eponymous template that tests whether a type is an integral or floating point type, whereas

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 12, 2017 08:32:03 k-five via Digitalmars-d-learn wrote: > On Thursday, 11 May 2017 at 19:59:55 UTC, Jordan Wilson wrote: > > On Thursday, 11 May 2017 at 18:07:47 UTC, H. S. Teoh wrote: > >> On Thu, May 11, 2017 at 05:55:03PM +, k-five via > >> > >> Digitalmars-d-learn wrote: >

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread k-five via Digitalmars-d-learn
On Friday, 12 May 2017 at 08:32:03 UTC, k-five wrote: On Thursday, 11 May 2017 at 19:59:55 UTC, Jordan Wilson wrote: On Thursday, 11 May 2017 at 18:07:47 UTC, H. S. Teoh wrote: On Thu, May 11, 2017 at 05:55:03PM +, k-five via Digitalmars-d-learn wrote: On Thursday, 11 May 2017 at 17:18:37

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-12 Thread k-five via Digitalmars-d-learn
On Thursday, 11 May 2017 at 19:59:55 UTC, Jordan Wilson wrote: On Thursday, 11 May 2017 at 18:07:47 UTC, H. S. Teoh wrote: On Thu, May 11, 2017 at 05:55:03PM +, k-five via Digitalmars-d-learn wrote: On Thursday, 11 May 2017 at 17:18:37 UTC, crimaniak wrote: > On Wednesday, 10 May 2017 at

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread Jordan Wilson via Digitalmars-d-learn
On Thursday, 11 May 2017 at 18:07:47 UTC, H. S. Teoh wrote: On Thu, May 11, 2017 at 05:55:03PM +, k-five via Digitalmars-d-learn wrote: On Thursday, 11 May 2017 at 17:18:37 UTC, crimaniak wrote: > On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote:

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 11, 2017 at 05:55:03PM +, k-five via Digitalmars-d-learn wrote: > On Thursday, 11 May 2017 at 17:18:37 UTC, crimaniak wrote: > > On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote: > - > > try this: > >

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread k-five via Digitalmars-d-learn
On Thursday, 11 May 2017 at 17:18:37 UTC, crimaniak wrote: On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote: - try this: https://dlang.org/phobos/std_exception.html#ifThrown Worked. Thanks. import std.stdio; import std.conv:

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread crimaniak via Digitalmars-d-learn
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

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread k-five via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 21:44:32 UTC, Andrei Alexandrescu wrote: On 5/10/17 3:40 PM, k-five wrote: --- I no need to handle that, so is there any way to prevent this exception? Use the "parse" family: https://dlang.org/phobos/std_conv.html#parse -- Andrei

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-11 Thread k-five via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 21:19:21 UTC, Stanislav Blinov wrote: On Wednesday, 10 May 2017 at 15:35:24 UTC, k-five wrote: On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov --- I don't understand. If you don't want to take

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 05/10/2017 05:40 AM, 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

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Andrei Alexandrescu via Digitalmars-d-learn
On 5/10/17 3:40 PM, 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

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 21:19:21 UTC, Stanislav Blinov wrote: "nothrow" does not turn off exceptions, it simply forbids throwing them in the enclosing scope (i.e. calling anything that might throw is not allowed). nothrow disallows the function scope to throw exceptions not derived from

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 15:35:24 UTC, k-five wrote: On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov wrote: On Wednesday, 10 May 2017 at 13:27:17 UTC, k-five wrote: Thanks, but I know about what are you saying. The user_apply[4] has so many possibilities and I cannot use

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread k-five via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov wrote: On Wednesday, 10 May 2017 at 13:27:17 UTC, k-five wrote: Thanks, but I know about what are you saying. The user_apply[4] has so many possibilities and I cannot use if-else That doesn't sound right. Either you've already

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 13:27:17 UTC, k-five wrote: Thanks, but I know about what are you saying. The user_apply[4] has so many possibilities and I cannot use if-else That doesn't sound right. Either you've already handled all the possible cases and thus expect the to! to not throw (can

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread k-five via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 13:12:46 UTC, Ivan Kazmenko wrote: On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote: -- I assume that an empty string is a valid input then. The question is, what value do you want `index` to have when

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Ivan Kazmenko via Digitalmars-d-learn
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

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Nicholas Wilson via Digitalmars-d-learn
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

How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread k-five via Digitalmars-d-learn
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.