Only want to say
Jacob Carlborg
doob at me.com
Tue Jan 12 13:52:48 UTC 2021
On Monday, 11 January 2021 at 22:12:15 UTC, ddcovery wrote:
> It's true. I suppose you mainly refer to assertions over
> shared (not exclusive) resources: you can't "snapshot" a
> pre/post state and demonstrate that your function is the
> responsible of this transformation.
>
> But the think here is I'm running a set of batch commands (not
> only 7z) over folders/files assuming that no other one is
> interested in.
>
> It is a really relaxed scenery, but enough for the tasks.
`assert` should be used to verify logical assumptions in your
program. To verify things in the environment, exceptions should
be used. You can drop the `in` and `out` contracts and use the
`enforce` function the same way as `assert` is used. It will
throw an exception if the condition doesn't hold.
Exceptions inheriting from the class `Exception` should be thrown
when there's an error related to the environment. I.e. a missing
file, failed to connect to a server and so on.
Exceptions inheriting from the class `Error` should be thrown
when there's a logical error in the program, this is what
`assert` does. This includes accessing an array outside of its
bounds, failing to handle all cases in a `final switch` statement
and so on.
`assert` and contracts can be removed from the code, depending on
which compiler flags are being used. Exceptions will always stay.
In your case, there can be something like anti-virus software
which is running in the background and decides to remove your
files which the program is processing.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list