Skip to content

A PPX rewriter to catch exceptions and wrap into options or results

Notifications You must be signed in to change notification settings

bensmrs/ppx_catch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ppx_catch

ppx_catch is a PPX rewriter to catch exceptions. It acts as a catch-all and transforms expressions into options or results.

Usage

catch.o

The catch.o extension wraps an expression into an option.

[%catch.o
  let i = Option.get None in
  i + 1
]

gives None, while

[%catch.o
  let i = Option.get (Some 2)
  in i + 1
]

gives Some 3. [%catch.o expression] behaves exactly like:

try Some expression with _ -> None

catch.r

The catch.r extension wraps an expression into a result.

[%catch.r Some 10;
  let i = Option.get None in
  i + 1
]

gives Error (Some 10), while

[%catch.r Some 10;
  let i = Option.get (Some 2)
  in i + 1
]

gives Ok 3. [%catch.r err; expression] behaves exactly like:

try Ok expression with _ -> err

About

A PPX rewriter to catch exceptions and wrap into options or results

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages