Re: Capturing error line on exception (SWI)



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
>


.



Relevant Pages

  • Re: Capturing error line on exception (SWI)
    ... > does anybody know how to get the error line of an error in swi prolog? ... You can intercept and act upon printing error messages by defining ... And anyway, the Prolog compiler doesn't read from current input, but from ... may modify the current input stream and do really weird things. ...
    (comp.lang.prolog)
  • Re: D8 and refactoring
    ... Just the compiler changes are listed below. ... without including the Variants unit in your applications, ... There are new library, deprecated, and platform directives, documented ...
    (borland.public.delphi.non-technical)
  • C Compiler Errors (For Real).
    ... These are some of the error messages produced by Apple's MPW C ... afternoon and decompiled the String resources for the compiler.) ... "Can't cast a void type to type void (because the ANSI spec. ... "This label is the target of a goto from outside of the block containing this ...
    (rec.humor.funny.reruns)
  • Re: The Decline of C/C++, the rise of X
    ... >> Jim points out later, and poorer error messages on a syntax error, as ... > clearly identify the position of an error is a feature of a compiler ...
    (comp.programming)
  • Re: The Decline of C/C++, the rise of X
    ... >> Jim points out later, and poorer error messages on a syntax error, as ... > clearly identify the position of an error is a feature of a compiler ...
    (comp.programming)