0
我有一個F#異常,它沒有被捕獲到正確的catch塊中。F#異常未被捕獲正確
下面是相關代碼:
exception ConfigFileVersionIncompatabilityException of string
[<XmlType("config")>]
type Configuration() = class
let thisVersion : string = "1.0"
let mutable fileVersion : string = thisVersion
[<XmlAttribute("version")>]
member x.FileVersion
with get() = fileVersion
and set v = if v <> thisVersion
then raise (ConfigFileVersionIncompatabilityException(String.Format("Was expecting version {0} but read version {1}.", thisVersion, v)))
end
module FilterFileFunctions =
let sampleConfigFilename = "sample.filters"
let readConfig (file : string) =
try
use xmlDoc = new StreamReader(file) in
let s = XmlSerializer(typeof<Configuration>)
s.Deserialize(xmlDoc) :?> Configuration |> Success
with
| ConfigFileVersionIncompatabilityException(s) ->
String.Format("Failed to read the configuration file: \"{0}\";\nThe following reason was given:\n{1}", file, s)
|> Failure
| ex ->
String.Format("Failed to read the configuration file: \"{0}\";\n{1}", file, ex)
|> Failure
的問題是,ex
catch塊捕捉ConfigFileVersionIncompatabilityException
例外,它應該由第一次塊被捕獲。
我試圖用:? System.Exception as ex
而不是ex
,它仍然表現相同。
我錯過了什麼嗎?
[主編1初始後之後分鐘以除去無關的代碼。]
它的工作原理!我真的應該發現,這個異常是從它顯示的消息中被包裹在另一個異常中的。呃,好吧。我將不得不更多地關注活動模式 - 儘管我在Haskell中工作過一些,但我仍然對F#很陌生。看來你的39.2k代表是當之無愧的,非常感謝! – paul 2011-03-25 18:43:58