2017-02-09 126 views
1

我無法在F# 4.0 spec內找到關於failwithf的信息。failwithf做什麼?

我的道歉,如果這是一個愚蠢的問題...

但是,什麼是failwithf

爲什麼要使用它?

+2

'failwith 「你好」'生成包含'Hello'異常。 'failwithf「Hello%s」「There」會生成一個包含'Hello There'的異常。這就像'printf' – FuleSnabel

回答

7

你可以找到MSDN文檔here

failwithf : StringFormat<'T,'Result> -> 'T 

它接受一個StringFormat很像printfsprintf,讓你包含類型安全的字符串格式化,例如:

failwithf "Error Code %i" 55 
+0

Tomas敦促不要使用這個:https://github.com/tpetricek/FSharp.Formatting/pull/225 –

+1

@ScottNimrod現在有一個編譯器警告:https://github.com/Microsoft/visualfsharp /問題/ 46 – TheInnerLight