many possible reasons of failure is an indication of trying to do
too much inside one function.
and of course, if you split up each piece of work into its own function,
you'd get a verbose API. get the balance.
in the mvc scenario, I usually follow the principal "failure in a model
does not fail a control" --- a function return failure to its caller
only when it cannot reasonably recover. a controller, when returned
failure from a model, can choose to present an error view instead; and
it still succeeds as a control, in that it shows the error as expected.
views shall never fail, unless given invalid input. but that is programmer
fault --- caller of functions are responsible of providing valid input.
【 在 heroes999 (heroes999) 的大作中提到: 】
: 一般来说要求由数据层(Model)驱动,View来渲染。
: 有个问题是数据层可能有各种各样的异常,比如打开文件失败、句柄失败等等,这些错误怎么传递给View或者Control以实现弹出不同的错误警告?
: 能想到的是枚举返回值和异常。直接在Model层或者Control层弹错误框是不是不太好?
: ...................
--
FROM 180.173.119.*