Re: nothrow and std.exception.ifThrown

2021-05-01 Thread novice2 via Digitalmars-d-learn
btw for my immediate needs i replace second delegate with value i.e. remove "lazy" from declaration and remove "()" in return so ifThrown loose some generity ```d nothrow CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2) (lazy scope T1 expression, scope

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Friday, 30 April 2021 at 13:42:49 UTC, Steven Schveighoffer wrote: On 4/30/21 9:24 AM, Meta wrote: My point is that I think marking the *function* nothrow is not correct, it's the second parameter that dictates the throwing of the result. And you can probably fix the second parameter to b

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Thursday, 29 April 2021 at 20:00:23 UTC, novice2 wrote: i dont understand why (templates too dificult for me yet), but if i comment "lazy" from T2, then compiler allow add "nothrow" to "ifThrown" ```d CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, /

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/30/21 9:24 AM, Meta wrote: On Friday, 30 April 2021 at 13:05:00 UTC, Steven Schveighoffer wrote: On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 express

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Friday, 30 April 2021 at 13:05:00 UTC, Steven Schveighoffer wrote: On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, lazy scope T2 errorHandler

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, lazy scope T2 errorHandler) nothrow ``` It's not marked as `nothrow` in the function's definition

Re: nothrow and std.exception.ifThrown

2021-04-29 Thread novice2 via Digitalmars-d-learn
Thank you Imperatron, Ali both variants ```d scope(failure) assert(0); ``` ```d collectException ``` works! Thank Meta The reason for this, apparently, is in the definition of `ifThrown` i tried to modify ifThrown adding nothrow, but compiler dont understand, that second parameter cant thr

Re: nothrow and std.exception.ifThrown

2021-04-29 Thread Ali Çehreli via Digitalmars-d-learn
On 4/29/21 9:02 AM, novice2 wrote: > format() can throw. In order to throw for an int, I added a foo(x) expression to prove that the code works. > I don't want embrace format into try..catch block, > and i found elegant std.exception.ifThrown. There are collectException and collectExceptionM

Re: nothrow and std.exception.ifThrown

2021-04-29 Thread Meta via Digitalmars-d-learn
On Thursday, 29 April 2021 at 16:02:20 UTC, novice2 wrote: Hello. I need use std.format.format() in nothrow function. format() can throw. For this case i have special default string. I don't want embrace format into try..catch block, and i found elegant std.exception.ifThrown. But DMD say "ifThro

Re: nothrow and std.exception.ifThrown

2021-04-29 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 29 April 2021 at 16:02:20 UTC, novice2 wrote: Hello. I need use std.format.format() in nothrow function. format() can throw. For this case i have special default string. I don't want embrace format into try..catch block, and i found elegant std.exception.ifThrown. But DMD say "ifThro

nothrow and std.exception.ifThrown

2021-04-29 Thread novice2 via Digitalmars-d-learn
Hello. I need use std.format.format() in nothrow function. format() can throw. For this case i have special default string. I don't want embrace format into try..catch block, and i found elegant std.exception.ifThrown. But DMD say "ifThrown not nothrow" https://run.dlang.io/is/kXtt5q ```d nothrow