Consider this (rather cut-down) function for catching the failure of pattern matching.
module Handle where import Control.Exception import System.IO.Unsafe wrap