4 people like it.

raiseAfterHandlers

Raises an exception again after attempting to run one or more handlers. Any failures in the handlers will be put into a new AggregateExeption. If no additional errors are raised, the original exception will be re-raised with a preserved stack trace.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
open System

let private internalPreserveStackTrace = typeof<Exception>.GetMethod("InternalPreserveStackTrace", System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.NonPublic)
let private preserveStackTrace (e:Exception) = internalPreserveStackTrace.Invoke(e, null) |> ignore; e

/// Raises the exception given after attempting to run each of the handlers in sequence.
/// If any exceptions are encountered during execution of the handlers, they will
/// be aggregated with the original exception. Otherwise the exception will be
/// raised in its original state, i.e. with preserved stack trace
let raiseAfterHandling (handlers:#seq<unit -> unit>) (e:Exception) =
    match handlers |> Seq.choose (fun handler -> try handler(); None with e -> Some e) |> Seq.toList with
    | [] -> preserveStackTrace e |> raise
    | list -> AggregateException(e :: list) |> raise
namespace System
val private internalPreserveStackTrace : Reflection.MethodInfo

Full name: Script.internalPreserveStackTrace
val typeof<'T> : Type

Full name: Microsoft.FSharp.Core.Operators.typeof
Multiple items
type Exception =
  new : unit -> Exception + 2 overloads
  member Data : IDictionary
  member GetBaseException : unit -> Exception
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member GetType : unit -> Type
  member HelpLink : string with get, set
  member InnerException : Exception
  member Message : string
  member Source : string with get, set
  member StackTrace : string
  ...

Full name: System.Exception

--------------------
Exception() : unit
Exception(message: string) : unit
Exception(message: string, innerException: exn) : unit
namespace System.Reflection
type BindingFlags =
  | Default = 0
  | IgnoreCase = 1
  | DeclaredOnly = 2
  | Instance = 4
  | Static = 8
  | Public = 16
  | NonPublic = 32
  | FlattenHierarchy = 64
  | InvokeMethod = 256
  | CreateInstance = 512
  ...

Full name: System.Reflection.BindingFlags
field Reflection.BindingFlags.Instance = 4
field Reflection.BindingFlags.NonPublic = 32
val private preserveStackTrace : e:Exception -> Exception

Full name: Script.preserveStackTrace
val e : Exception
Reflection.MethodBase.Invoke(obj: obj, parameters: obj []) : obj
Reflection.MethodBase.Invoke(obj: obj, invokeAttr: Reflection.BindingFlags, binder: Reflection.Binder, parameters: obj [], culture: Globalization.CultureInfo) : obj
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val raiseAfterHandling : handlers:#seq<(unit -> unit)> -> e:Exception -> 'b

Full name: Script.raiseAfterHandling


 Raises the exception given after attempting to run each of the handlers in sequence.
 If any exceptions are encountered during execution of the handlers, they will
 be aggregated with the original exception. Otherwise the exception will be
 raised in its original state, i.e. with preserved stack trace
val handlers : #seq<(unit -> unit)>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
module Seq

from Microsoft.FSharp.Collections
val choose : chooser:('T -> 'U option) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.choose
val handler : (unit -> unit)
union case Option.None: Option<'T>
val e : exn
union case Option.Some: Value: 'T -> Option<'T>
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
val raise : exn:Exception -> 'T

Full name: Microsoft.FSharp.Core.Operators.raise
Multiple items
val list : exn list

--------------------
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
Multiple items
type AggregateException =
  inherit Exception
  new : unit -> AggregateException + 6 overloads
  member Flatten : unit -> AggregateException
  member GetBaseException : unit -> Exception
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member Handle : predicate:Func<Exception, bool> -> unit
  member InnerExceptions : ReadOnlyCollection<Exception>
  member ToString : unit -> string

Full name: System.AggregateException

--------------------
AggregateException() : unit
AggregateException(message: string) : unit
AggregateException(innerExceptions: Collections.Generic.IEnumerable<exn>) : unit
AggregateException([<ParamArray>] innerExceptions: exn []) : unit
AggregateException(message: string, innerException: exn) : unit
AggregateException(message: string, innerExceptions: Collections.Generic.IEnumerable<exn>) : unit
AggregateException(message: string, [<ParamArray>] innerExceptions: exn []) : unit
Raw view Test code New version

More information

Link:http://fssnip.net/6w
Posted:13 years ago
Author:Sebastian Good
Tags: exception