Hide Table of Contents

Error Handling

If an error occurs when an expression is evaluated, Lisp prints an error message. However, in many cases, printing only the system’s error message is not sufficient. Often, you also want to make sure that certain states and modes are restored when a function is cancelled.

The *error* function lets you to define your own error handler. The function has only one argument: a string to which the error message text of the system is passed. Instead of printing the message, the Lisp Interpreter executes your error handler. Within your error handler you can evaluate the message and perform functions to restore the settings of modified system variables, set states back as they were before your routine was performed, etc.

Using the expression (setq *error* nil) restores the default error handler of the system.

Example

The following is an example for a function definition for error handling:

(defun *error* (msg)
  (if (= msg "User break")
    (setvar "OSMODE" osmode_save)
    (progn
      (princ "The following error occurred: ")
      (princ msg)
      (terpri)
    )
  )
  (setq *error* nil)
  (princ)
 )

Related Functions

*error*



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Error Handling
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2019 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.