Re: Capturing error line on exception (SWI)
- From: Jan Wielemaker <jan@xxxxxxxxxxxx>
- Date: 30 Jun 2005 13:48:28 GMT
On 2005-06-30, Mauro Di Nuzzo <picorna@xxxxxxxxx> wrote:
> Hi,
>
> does anybody know how to get the error line of an error in swi prolog?
> Before trying to explain I give you an example:
>
> go :-
> ...,
> ensure_loaded('myfile.pl'),
> ...
>
> if an error occurs in 'myfile.pl' an error message is printed which tell me
> the error line no.
> But suppose I am currently use catch/3 or call_cleanup/3...
I'm not sure I get what you're after. There is no point putting a
catch/3 around ensure_loaded/1 to catch errors while loading the file.
As far as I know ensure_loaded/1 only throws an exception of the
filename argument is of the wrong type or the file cannot be opened.
Once the file is open the compilation loop itself uses catch/3 and
print_message/2 to catch and print error messages. This is done to
prevent the compiler from stopping after the first error. The line
number is part of the exception context (i.e. the 2nd argument of the
error/2 tuple).
You can intercept and act upon printing error messages by defining
message_hook/3. That might solve your problem.
> how can I get the error line number?
> I firstly tried to access the stream_property/2 (with $stream_position)
> using current_input/1, but I realized that the stream associated with
> 'myfile.pl' is suddenly closed after an error occurs (ie. it does no longer
And anyway, the Prolog compiler doesn't read from current input, but from
an explicitely passed input stream to avoid trouble with directives that
may modify the current input stream and do really weird things. You can
get the current stream through prolog_load_context/2.
> Does any way to get the error line number exist, when we consult external
> files?
I hope the above suffices. Otherwise elaborate a bit on what you exactly
want to do.
Cheers --- Jan
.
- References:
- Capturing error line on exception (SWI)
- From: Mauro Di Nuzzo
- Capturing error line on exception (SWI)
- Prev by Date: How make qcompile/1 silent? (SWI)
- Next by Date: Re: How make qcompile/1 silent? (SWI)
- Previous by thread: Capturing error line on exception (SWI)
- Next by thread: How make qcompile/1 silent? (SWI)
- Index(es):
Relevant Pages
|
|