Programs should intercept and attempt to process errors instead of allowing control to pass to *error* when possible.
The vl-catch-all-apply function is designed to invoke any function, return a value from the function, and trap any error that may occur. The function
requires two arguments:
- A symbol identifying a function or lambda expression
- A list of arguments to be passed to the called function
The importance of vl-catch-all-apply is the ability to catch errors and allow your program to continue execution. The following example uses vl-catch-all-apply to divide two numbers:
(setq catchit (vl-catch-all-apply '/ '(50 5)))
The result from this example is the same as if you had used apply to perform the division or just used / to divide the provided numbers.
The following example uses vl-catch-all-apply to divide two numbers, and one of the numbers being zero:
(setq catchit (vl-catch-all-apply '/ '(5 0)))
The result from this example returns a VL-CATCH-ALL-APPLY-ERROR object which can be interpreted using vl-catch-all-error-message. You can use the type function to make sure you are working with an error object before calling vl-catch-all-error-message.
The following example checks for an error object and returns the error message:
(if (vl-catch-all-error-p catchit)
"divide by zero"