Yet another Error Handler question.

Discussion in 'AutoCAD' started by SkintSubby, Oct 21, 2004.

  1. SkintSubby

    SkintSubby Guest

    Sorry to post yet another Error Handling question, but it's doing my nut in.....

    I have the following code:-


    (if (= anyvariable nil) (*error*)) ; at various parts of the lisp

    ;error handler
    (defun *error* (msg)
    (princ "Error: No Objects Selected, Aborting")
    (setvar "cmdecho" echo)
    (setvar "osmode" osmd)
    (princ)
    );end defun

    Which all seams to work, however when "Tools--->Check text in editor" on Vlisp I get the error :-
    ; warning: too few arguments: (*ERROR*) at the "IF"

    What am I doing wrong?

    Thanks for taking the time to look at the question, all help appreciated.
     
    SkintSubby, Oct 21, 2004
    #1
    1. Advertisements

  2. Look closely at your *Error* definition. Are there any arguments for the
    function? Are you providing those arguments when you call the function?

    --
    R. Robert Bell


    Sorry to post yet another Error Handling question, but it's doing my nut
    in.....

    I have the following code:-


    (if (= anyvariable nil) (*error*)) ; at various parts of the lisp

    ;error handler
    (defun *error* (msg)
    (princ "Error: No Objects Selected, Aborting")
    (setvar "cmdecho" echo)
    (setvar "osmode" osmd)
    (princ)
    );end defun

    Which all seams to work, however when "Tools--->Check text in editor" on
    Vlisp I get the error :-
    ; warning: too few arguments: (*ERROR*) at the "IF"

    What am I doing wrong?

    Thanks for taking the time to look at the question, all help appreciated.
     
    R. Robert Bell, Oct 21, 2004
    #2
    1. Advertisements

  3. SkintSubby

    Tom Smith Guest

    It should be (*error* <message>). The *error* function takes an argument,
    which can be an empty string (*error* "") if you have no error message to
    display. Some people are very adamant about programming an error handler
    this way, however standard Acad error handler will also accept (*error* nil)
    for no error message.

    Unless you're going to repeat this same block of code, with slight
    modifications, in every lisp program you write, IMHO it's bad practice to
    hard-code the error message in the error handler like this. Remember that
    any "error" including cancelling the routine will cause your error handler
    to run, and your message will nearly always be spurious. You need to let
    Acad fill in the message most of the time, except when you're explicitly
    calling the function. This would be better:

    (defun *error* (msg)
    (princ msg)
    <etc..>
    )



    If you want this to run when nothing is selected -- which would contradict
    normal Acad conventions, since it normally keeps prompting you until you do
    make a selection -- your calling routine should look something like this:

    (defun c:widget (/ sset <etc.>)
    (if (setq sset (ssget))
    (run-widget-function)
    (*error* "Nothing selected.")
    )
    (princ)
    )

    Using the mathmatical equality function "=" to compare somethingness to
    nothingness is not really proper. If you want test for nil,
    use (if (not <variable>) (<whatever>)). As in my example above, it's nearly
    always possible -- and can be clearer -- to turn this around and use the
    opposite test (if <variable> (<whatever>)) which eliminates one unecessary
    operation.
     
    Tom Smith, Oct 21, 2004
    #3
  4. SkintSubby

    SkintSubby Guest

    Gent's

    Sorted!!! Thanks for taking the time to help, and pointing me in the correct direction..

    MG,
     
    SkintSubby, Oct 21, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.