Why is the raising of an exception a side effect?

前端 未结 5 1904
清歌不尽
清歌不尽 2020-12-13 05:50

According to the wikipedia entry for side effect, raising an exception constitutes a side effect. Consider this simple python function:

def foo(arg):
    if          


        
5条回答
  •  被撕碎了的回忆
    2020-12-13 06:42

    From the first line:

    "In computer science, a function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions or the outside world"

    The state it modifies is the termination of the program. To answer your other question about why it is not a pure function. The function is not pure because throwing an exception terminates the program therefore it has a side effect (your program ends).

提交回复
热议问题