What should happen when the assert message expression throws?

H. S. Teoh hsteoh at qfbox.info
Thu Dec 8 16:02:14 UTC 2022


On Thu, Dec 08, 2022 at 04:03:35PM +0100, Timon Gehr via Digitalmars-d wrote:
> On 11/26/22 13:32, Ali Çehreli wrote:
> > - If configFile was a string input by the user, then the following
> > is appropriate:
> > 
> >    enforce(exists(configFile), /* ... */)
> > 
> > - If configFile was a string representing a file e.g. that has just
> > been generated by the same program, then the following is
> > appropriate:
> > 
> >    assert(exists(configFile), /* ... */)
> > 
> > Only the programmer knows.
> 
> I don't think it is appropriate to assert that the filesystem is not
> being changed concurrently by some other process unless the OS
> provides explicit functionality to enforce it.

Yeah, for checking the existence of a file I'd use enforce, not assert.
Assert is for catching logic errors in the program; a missing file in
the filesystem isn't a logic error, it's either an installation problem
(your program wasn't installed properly) or an incidental issue (user
removed the drive for whatever reason, or hardware is failing).


T

-- 
Study gravitation, it's a field with a lot of potential.


More information about the Digitalmars-d mailing list