Skip to content

Confusion about re-throwing an exception #101

@jmagaram

Description

@jmagaram

I'm trying to catch and work with an Error, but don't know for sure what I'm receiving in the exception. If I test using Error.fromException and that fails and returns None I want to throw it again, but I can't. I need to use the OCaml raise function which seems to be available to me. Maybe the type of Error.raise needs to be loosened? Do we need an Error.raiseAny?

let f = () => {
  try {
    Console.log("do things")
  } catch {
  | _ as e =>
    switch e->Error.fromException {
    | Some(x) => Console.log("Handled!")
    | None => Error.raise(e) // Compile error, expects an Error.t
    | None => raise(e) // Works!
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions