What should happen when the assert message expression throws?

Timon Gehr timon.gehr at gmx.ch
Fri Dec 9 19:15:41 UTC 2022


On 12/9/22 15:36, kdevel wrote:
> 
> Now: A file system is essentially a key/value store. (1) can also be
> written as
> 
>     auto value = readText (key);
> 
> With a nicer notation this becomes
> 
>     auto value = obj [key]; // (2)
> ...

You mean with a deliberately more confusing notation.

> where obj is an instance of some Filesystem class. IMNSHO it is hard
> to explain, why in case of
> 
>     string[string] obj;
>     string key;
> 
> or
> 
>     string [] obj;
>     int key;
> 
> the expression (2) throws an Error (capital E) while in the case of
> 
>     Filesystem obj;
>     string key;
> 
> it throws an Exception.
It is not hard to explain. The version throwing an error is a more 
fundamental building block that can be used to implement the version 
throwing an exception. The file system does not expose the more 
low-level operation because the file system is shared between multiple 
processes and it also does not expose primitives to synchronize file 
system accesses. I.e., you can't be sure the programmer is to blame for 
attempting to e.g. open an nonexistent file.

It could be different, but that would require a OS design that supports 
some sort of filesystem ownership semantics.


More information about the Digitalmars-d mailing list