Skip to content

Instantly share code, notes, and snippets.

@jdh30
Last active February 28, 2020 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdh30/034c5de27a1ef386e7534ad9cf933122 to your computer and use it in GitHub Desktop.
Save jdh30/034c5de27a1ef386e7534ad9cf933122 to your computer and use it in GitHub Desktop.
Avoiding the undebuggable type initialization exception in F#
let mutable globalException : System.Exception = null // Compiler generated
let myGlobal =
if isNull globalException then // Compiler generated
try // Compiler generated
System.IO.File.ReadAllText "DoesNotExist.txt"
with e -> // Compiler generated
globalException <- e // Compiler generated
Unchecked.defaultof<_> // Compiler generated
else Unchecked.defaultof<_> // Compiler generated
let main args =
if not(isNull globalException) then // Compiler generated
raise globalException // Compiler generated
printfn "%s" myGlobal
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment