Erratic behaviour when raising exception from foreign code

I considered several times to just pick up the defines from sqlite and drop them in the Prolog wrapper of the sqlite bindings; then parse the options in Prolog and give the flags as an int. This creates yet another mixed layer though :-/