Re: Capturing error line on exception (SWI)
- From: "Mauro Di Nuzzo" <picorna@xxxxxxxxx>
- Date: Tue, 19 Jul 2005 20:58:58 GMT
Sorry... My brain's backtracking...
Consider consulting a .pl file like this:
:- true,
true,
2 is X,
true, ...
Instantiation error appears to result on line 1.
In other words, many raised exception refer to the line of the directive :-
operator.
Now suppose I have a source code of 2000 lines, with only one directive on
line 1...
Debug will be nearly impossible!
I hope this is not another my mistake...
Cheers, M
"Jan Wielemaker" <jan@xxxxxxxxxxxx> ha scritto nel messaggio
news:slrndc7u1c.qfg.jan@xxxxxxxxxxxxxxx
> 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
>
.
- Follow-Ups:
- Re: Capturing error line on exception (SWI)
- From: Jan Wielemaker
- Re: Capturing error line on exception (SWI)
- Prev by Date: Re: Newbie without any idea!!!
- Next by Date: Re: Rule generation
- Previous by thread: Re: Newbie without any idea!!!
- Next by thread: Re: Capturing error line on exception (SWI)
- Index(es):
Relevant Pages
|