HP Forums

Full Version: How do I raise a user-defined error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to generate a user-defined error in a Prime program that can be trapped using IFERR...THEN... ?

I could always use a 'divide by 0' to force an error but that won't be very intuitive for the user.
I think there is no way to trigger an user defined error but you are right, dividing by zero could be a way Smile

The error number is stored in Ans, so you could do something after the error is triggered.
In what sense do you mean "raise a user-defined error"? Do you already know that an error occurred at that point? If so, then a simple message box with the error string might do the job. On the other hand, if you want to generate an actual error, then your idea is likely the only way to generate an error in a controlled way. The error number is stored in Ans, but it will be useless if you forced a divide-by-0 error. You could, however, have your own errn and errmsg variable that you can set. Since you are forcing an error, then save your error number or string to an appropriate variable, generate the error, and use your variable for the error handling. It could be something as simple as return(errmsg) if you want the program to stop execution.

EDIT: It seems to me that you're eventual use of IFERR THEN END is merely to create a controlled break. Why not simply use an appropriate return()?
Reference URL's