0

I am new to OCaml which I installed via opam. My compiler is dune. Each time I build my project and run it, it crashes but I get no information from where it crashes in the code.

A friend of mine who is doing the same thing get information about the line where it crashes.

If anyone have an idea it will be incredible !

Best regards,

2 Answers2

1

You could add the following in you main, which turns on the recording of exception backtraces:

let main =
  record_backtrace true;
...

Alternativelly, you can set the b flag through the OCAMLRUNPARAM variable.

ghilesZ
  • 1,502
  • 1
  • 18
  • 30
  • How do you set this variable in dune? – Kris Jun 18 '22 at 01:46
  • this is an environment variable, which means you have to set it in your shell before executing your program. EG: ````export OCAMLRUNPARAM=b; dune exec ./myprog.exe```` – ghilesZ Jun 18 '22 at 06:01
1

you can try using try\catch, exceptions and printing to find where the problem is at.

in case the exception is something you have raised, you can try to replace it with a costume exception to get the various details.

exception Yourexception of string;;

raise (Yourexception "the problem is here") ;;

if the problem is an OS exception, such as stack overflow, you can try placing prints all over the place, and slowly pinpoint the exact location

print_string( "1\n");

and when all else fail, use try and catch to slowly pinpoint the location (you can google the exception to help pinpoint the cause. for example finding that list raise the exception or something)

try (-your code-)
with exception -> (- print or handle or whatever - );;

these steps help with most of the languages, so its nice to remember them