У меня есть простая иерархия исключений:
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)
и эти три (фиктивные) функции:
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))
Легко увидеть, что при вызове ThirdFunction:
- firstFunction вызывает исключение FirstLevelException
- secondFunction перехватывает его, помещает в исключение SecondLevelException и выбрасывает
- thirdFunction перехватывает его, помещает его в исключение ThirdLevelException и выбрасывает
- вызывающий абонент может поймать исключение ThirdLevelException.
Все хорошо.Теперь я изменяю ThirdFunction следующим образом:
member this.ThirdFunction a =
25 |>
try
this.SecondFunction
with
| :? SecondLevelException as ex -> raise (new ThirdLevelException("three", ex))
все становится странным: похоже, что сопоставление с шаблоном в ThirdFunction больше не работает, а SecondLevelException распространяется вплоть до вызывающей функции ThirdFunction, безбыть заключенным в ThirdLevelException.
Я уверен, что есть логическое объяснение, которое мой C # -деформированный разум не может видеть.Может кто-нибудь, пожалуйста, пролить немного света?