chansey97
2022-6-10 20:21:20

I have a question about programming languages and design patterns (which is not related to Racket though I don’t know if it’s appropriate to post here). In what scenarios would we allow a procedure to execute silently when the inputs are wrong? For example, we usually like to write the following program: int do_somthing1(int a) { if a == -1 throw exception. // It is something like constract in Racket } The idea is that a program fails as quickly as possible after a bug has been detected.

However, is there any application (or requirement) that allows the do_somthing1 to execute silently (e.g. return -1 ) instead of throwing exception? Of course, log messages are allowed to facilitate debugging. For example, a = -1 b = do_somthing1(a); print("111"); c = do_somthing2(b); print("222"); d = do_somthing3(c); print("333"); e = do_somthing4(); print("444"); Since a = -1, the execution of do_somthing1, do_somthing2, do_somthing3 is silent (i.e. doesn’t do anything), but print("111"); print("222"); print("333"); e = do_somthing4(); print("444"); execute normally because they do not depend on a. Could you think of any such scenarios in practice? Thanks.


ben.knoble
2022-6-10 21:36:05

The default shell options basically do this: command failure does not abort the script. You have to use set -e (and you usually want set -u for similar reasons, and in bash set -o pipefail is also needed) to get the “fail on failure” behavior.


chansey97
2022-6-10 21:53:18

Interesting. You mentioned command. Maybe command-based programs use this mechanism?