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


Groups > comp.lang.postscript > #1556

Wrote a fatalError function

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.postscript
Subject Wrote a fatalError function
Organization Decebal Computing
Date 2013-08-01 16:41 +0200
Message-ID <878v0l8odt.fsf@Aspire.decebal.nl> (permalink)

Show all headers | View raw


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

Back to comp.lang.postscript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

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

csiph-web