1 people like it.

Raise an ArgumentException

Convenience function to easily throw an argument exception with a helpful string description. Looks simple, but was hard to figure out.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
/// <summary>
/// Convenience function to raise an ArgumentException
/// </summary>
/// <param name="format">The input formatter</param>
let raiseArgEx format =
    Printf.ksprintf (fun s -> raise (System.ArgumentException(s))) format

let n = -1

if n < 0 then
    // the following code can be replaced
    // let msg = sprintf "n = %d; must be >= 0" n
    // raise(ArgumentException(msg))
    raiseArgEx "n = %d; must be >= 0" n
val raiseArgEx : format:Printf.StringFormat<'a,'b> -> 'a

Full name: Script.raiseArgEx


 <summary>
 Convenience function to raise an ArgumentException
 </summary>
 <param name="format">The input formatter</param>
val format : Printf.StringFormat<'a,'b>
module Printf

from Microsoft.FSharp.Core
val ksprintf : continutation:(string -> 'Result) -> format:Printf.StringFormat<'T,'Result> -> 'T

Full name: Microsoft.FSharp.Core.Printf.ksprintf
val s : string
val raise : exn:System.Exception -> 'T

Full name: Microsoft.FSharp.Core.Operators.raise
namespace System
Multiple items
type ArgumentException =
  inherit SystemException
  new : unit -> ArgumentException + 4 overloads
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member Message : string
  member ParamName : string

Full name: System.ArgumentException

--------------------
System.ArgumentException() : unit
System.ArgumentException(message: string) : unit
System.ArgumentException(message: string, innerException: exn) : unit
System.ArgumentException(message: string, paramName: string) : unit
System.ArgumentException(message: string, paramName: string, innerException: exn) : unit
val n : int

Full name: Script.n
Raw view New version

More information

Link:http://fssnip.net/mB
Posted:5 years ago
Author:Wallace Kelly
Tags: exceptions