HP Forums
How do I raise a user-defined error? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How do I raise a user-defined error? (/thread-8218.html)



How do I raise a user-defined error? - BruceH - 04-20-2017 10:51 PM

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.


RE: How do I raise a user-defined error? - eried - 04-21-2017 09:01 AM

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.


RE: How do I raise a user-defined error? - Han - 04-21-2017 02:05 PM

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()?