Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1556 > unrolled thread

Wrote a fatalError function

Started byCecil Westerhof <Cecil@decebal.nl>
First post2013-08-01 16:41 +0200
Last post2013-08-01 19:41 +0200
Articles 4 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  Wrote a fatalError function Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 16:41 +0200
    Re: Wrote a fatalError function luser- -droog <mijoryx@yahoo.com> - 2013-08-01 09:46 -0700
      Re: Wrote a fatalError function luser- -droog <mijoryx@yahoo.com> - 2013-08-01 09:50 -0700
      Re: Wrote a fatalError function Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 19:41 +0200

#1556 — Wrote a fatalError function

FromCecil Westerhof <Cecil@decebal.nl>
Date2013-08-01 16:41 +0200
SubjectWrote a fatalError function
Message-ID<878v0l8odt.fsf@Aspire.decebal.nl>
In another thread I needed to signal an error and I did not want a
stack trace. This is something you can use more often I think, so I
made a general function for it. You can choose if you want to show a
message or not (in my example the message is shown in the function
itself) and if you want to see a stack trace. (Default not.)

The funtion:
    % To quit the program when there was an error, default the stack is not shown
    % Only print the errorMessage when it is not empty
    % errorMessage [surpressStack]  fatalError  -
    /fatalError {
        dup type /booleantype ne {
            true
        } if
        {
            errordict/handleerror {
                interrupted
            } put
        } if
        dup () ne {
            ==
        } {
            pop
        } ifelse
        /USER-DEFINED-ERROR cvx /unregistered signalerror
        /handleerror signalerror
    } def

And an example of how I use it:
    % to be called at the end of a program
    % if stack empty (as it should be) say this
    % otherwise signal this and show the stack
    % ends the program to circumvent/signal it being called to soon
    /endProgram {
        count 0 eq {
            (Stack empty at end of program) ==
            quit
        } {
            count dup
            1 eq {
                (ERROR: object on stack at the end of the program)   ==
            } {
                (ERROR: objects on stack at the end of the program)  ==
            } ifelse
            {
                (Unexpected object on stack: ) print
                ==
            } repeat
            () fatalError
        } ifelse
        (This message should never be shown)       ==
        (If it is, the quit operater is overruled) ==
    } def

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#1558

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-08-01 09:46 -0700
Message-ID<495cc790-b3a1-4b6a-bc5b-e8fd88a4de0b@googlegroups.com>
In reply to#1556
On Thursday, August 1, 2013 9:41:18 AM UTC-5, Cecil Westerhof wrote:
> In another thread I needed to signal an error and I did not want a
> 
> stack trace. This is something you can use more often I think, so I
> 
> made a general function for it. You can choose if you want to show a
> 
> message or not (in my example the message is shown in the function
> 
> itself) and if you want to see a stack trace. (Default not.)
> 
> 
> 
> The funtion:
> 
>     % To quit the program when there was an error, default the stack is not shown
> 
>     % Only print the errorMessage when it is not empty
> 
>     % errorMessage [surpressStack]  fatalError  -
> 
>     /fatalError {
> 
>         dup type /booleantype ne {
> 
>             true
> 
>         } if
> 
>         {
> 
>             errordict/handleerror {
> 
>                 interrupted

This should be `interrupt` or else you may trip
an infinite loop of /undefined errors.

And see my post in the other thread. /handleerror
is responsible for printing the error message.

>             } put
> 
>         } if
> 
>         dup () ne {
> 
>             ==
> 
>         } {
> 
>             pop
> 
>         } ifelse
> 
>         /USER-DEFINED-ERROR cvx /unregistered signalerror
> 
>         /handleerror signalerror

This line is unnecessary (and wrong). /signalerror should 
always be called with 2 arguments, and /handleerror is not
an appropriate error-name (even though it lives in the same
dict, errordict).

/signalerror calls interrupt.
/interrupt calls stop.
/stop unwinds the execstack and yields `false` to the outer 
stopped context (the executive for an interactive session, 
the jobserver for a batch session). This outer context then
calls errordict/handleerror. So the first call to signalerror
will do all this.

> 
>     } def
> 
> 
> 
> And an example of how I use it:
> 
>     % to be called at the end of a program
> 
>     % if stack empty (as it should be) say this
> 
>     % otherwise signal this and show the stack
> 
>     % ends the program to circumvent/signal it being called to soon
> 
>     /endProgram {
> 
>         count 0 eq {
> 
>             (Stack empty at end of program) ==
> 
>             quit
> 
>         } {
> 
>             count dup
> 
>             1 eq {
> 
>                 (ERROR: object on stack at the end of the program)   ==
> 
>             } {
> 
>                 (ERROR: objects on stack at the end of the program)  ==
> 
>             } ifelse
> 
>             {
> 
>                 (Unexpected object on stack: ) print
> 
>                 ==
> 
>             } repeat
> 
>             () fatalError
> 
>         } ifelse
> 
>         (This message should never be shown)       ==
> 
>         (If it is, the quit operater is overruled) ==
> 
>     } def
> 
> 
> 
> -- 
> 
> Cecil Westerhof
> 
> Senior Software Engineer
> 
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#1559

Fromluser- -droog <mijoryx@yahoo.com>
Date2013-08-01 09:50 -0700
Message-ID<a0a6422f-fb20-4338-a449-82f3fe9ba102@googlegroups.com>
In reply to#1558
On Thursday, August 1, 2013 11:46:35 AM UTC-5, luser- -droog wrote:

> 
> /signalerror calls interrupt.
> 
> /interrupt calls stop.
> 
> /stop unwinds the execstack and yields `false` to the outer 

should be:
                                  yields `true`

> 
> stopped context (the executive for an interactive session, 
> 
> the jobserver for a batch session). This outer context then
> 
> calls errordict/handleerror. So the first call to signalerror
> 
> will do all this.
> 
> 

[toc] | [prev] | [next] | [standalone]


#1560

FromCecil Westerhof <Cecil@decebal.nl>
Date2013-08-01 19:41 +0200
Message-ID<874nb98g18.fsf@Aspire.decebal.nl>
In reply to#1558
Op donderdag 1 aug 2013 18:46 CEST schreef luser:

>> % To quit the program when there was an error, default the stack is
>>   not shown
>>
>> % Only print the errorMessage when it is not empty
>>
>> % errorMessage [surpressStack]  fatalError  -
>>
>> /fatalError {
>>
>> dup type /booleantype ne {
>>
>> true
>>
>> } if
>>
>> {
>>

>>
>> interrupted
>
> This should be `interrupt` or else you may trip
> an infinite loop of /undefined errors.

Done.


>> /USER-DEFINED-ERROR cvx /unregistered signalerror
>>
>> /handleerror signalerror
>
> This line is unnecessary (and wrong). /signalerror should 
> always be called with 2 arguments, and /handleerror is not
> an appropriate error-name (even though it lives in the same
> dict, errordict).

Some garbage that was not correctly deleted after the row of edits.
Luckily it would not get there, but deleted also.

Thanks for all the help you are giving.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web