What should happen when the assert message expression throws?

H. S. Teoh hsteoh at qfbox.info
Fri Dec 9 18:26:31 UTC 2022


On Fri, Dec 09, 2022 at 02:36:04PM +0000, kdevel via Digitalmars-d wrote:
> On Thursday, 8 December 2022 at 16:02:14 UTC, H. S. Teoh wrote:
> 
> [...]
> 
> > Yeah, for checking the existence of a file I'd use enforce, not
> > assert.
> 
> You would write
> 
>    enforce (exists (filename));
>    auto text = readText (filename);
> 
> instead of simply
> 
>    auto text = readText (filename);  // (1)
> 
> ? I mean isn't the enforce redundant and also prone to TOCTTOU?
[...]

No, I meant, *if* I wanted to check for the existence of a file, I would
use enforce rather than assert.  If I was going to just read the file, I
might as well just catch the exception when opening it failed. It would
be pointless to use .enforce to check for its existence.


T

-- 
"Holy war is an oxymoron." -- Lazarus Long


More information about the Digitalmars-d mailing list