我有这个简单的异常层次结构:
type FirstLevelException(msg) = inherit System.Exception (msg)
type SecondLevelException(msg, inner) = inherit System.Exception (msg, inner)
type ThirdLevelException(msg, inner) = inherit System.Exception (msg, inner)
Run Code Online (Sandbox Code Playgroud)
和这三个(虚拟)功能:
member this.FirstFunction a =
raise (new FirstLevelException("one"))
member this.SecondFunction a =
try
this.FirstFunction a
with
| :? FirstLevelException as ex -> raise (new SecondLevelException("two", ex))
member this.ThirdFunction a =
try
this.SecondFunction 25
with
| :? SecondLevelException as ex -> raise (new ThirdLevelException("three", ex))
Run Code Online (Sandbox Code Playgroud)
当你调用ThirdFunction时很容易看到:
都好.现在我按以下方式更改thirdFunction:
member this.ThirdFunction a =
25 |>
try …Run Code Online (Sandbox Code Playgroud) f# ×1