Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all exception-causing functions in OCaml sources

Tags:

ocaml

It is widely known that a huge chunk of standard OCaml functions and a lot of common stdlib and 3rd party libraries are often contain functions that can throw exceptions. It can be very tricky to handle, especially if most of the program is written in a functional way. Are there any ways or tools to list/catch all the functions that throw exceptions by auditing the sources?

like image 263
Anton Kochkov Avatar asked Sep 12 '25 17:09

Anton Kochkov


2 Answers

Best solution I know is to use ocp-grep:

ocp-grep Pervasives.raise
like image 133
Louis Roché Avatar answered Sep 15 '25 07:09

Louis Roché


There has been an attempt to build a static analyzer for exceptions, located at https://github.com/OCamlPro/ocp-analyzer. However, last time I checked it crashed even on very simple programs and that the repository consists in a single commit, I'd say that it might be useful only as a starting point for writing a proper analyzer.

like image 21
Virgile Avatar answered Sep 15 '25 07:09

Virgile