Why throw an exception in Prolog instead a simple fail?

417 Views Asked by At

I'm programming in Prolog and sometimes I want to get a fail but instead I get an exception, which I can't understand why should be a difference between them. If something couldn't execute that's mean that the predicate didn't succed, so it's a simple fail. Am I missing something?

1

There are 1 best solutions below

2
Paulo Moura On

A failure means that what you're trying to prove is false. An exception means that what you're trying to prove doesn't make sense (e.g. trying to compute the square root of an atom) for some reason or that you bumped into some system limitation (e.g. exhausting available memory).

But you can easily convert any exception into a failure by writing:

catch(Goal, _, fail)