2017-02-09 127 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