Home > Blockchain >  Implicit call stack in the exception type
Implicit call stack in the exception type

Time:09-29

I'm trying to store call stacks in the exception types. I can add HasCallStack constraint to the exception type like that:

data AException = HasCallStack => AException !String !Int
  deriving (Typeable, Exception)
deriving instance Show AException

Is it possible to extract the call stack from such type, without profiling enabled?

As a workaround I could put CallStack field explicitly into exception type and fill it every time manually, but I'm wondering if this can be done automatically?

CodePudding user response:

I think you can just use callStack.

getCS :: AException -> CallStack
getCS (AException _ _) = callStack

It is important that you pattern match; this brings the HasCallStack constraint witness into scope.

  • Related