How to check for and trap a CAS error in a program?
|
11-30-2018, 03:27 PM
Post: #1
|
|||
|
|||
How to check for and trap a CAS error in a program?
I have the following sample program in the emulator, latest ROM.[/quote]
PHP Code: EXPORT FOO() Quote:sin As you can see from the messages, the IFERR error handler didn't trap the CAS error. Is there another 'official' way to do this? |
|||
11-30-2018, 05:48 PM
Post: #2
|
|||
|
|||
RE: How to check for and trap a CAS error in a program?
You can trap CAS errors in CAS programs.
|
|||
12-01-2018, 02:01 AM
Post: #3
|
|||
|
|||
RE: How to check for and trap a CAS error in a program?
If your expected result will never be a string, testing for a string after could also work for you I think.
TW Although I work for HP, the views and opinions I post here are my own. |
|||
12-01-2018, 02:48 PM
Post: #4
|
|||
|
|||
RE: How to check for and trap a CAS error in a program?
Thanks Tim.
Actually it is the part() function that I want to trap and it can return a string legitimately. After reading Parisse's suggestion, it occurred to me that rather than try and trap the error from part() in my main code, I could just use a separate #cas...#end bracketed function which calls part() with 1, 2, 3, .. etc until it fails and then return the max value to use as the loop upper bound in my main code with no worries about errors. |
|||
12-01-2018, 03:41 PM
Post: #5
|
|||
|
|||
RE: How to check for and trap a CAS error in a program? | |||
12-02-2018, 02:25 AM
(This post was last modified: 12-02-2018 02:25 AM by Jacob Wall.)
Post: #6
|
|||
|
|||
RE: How to check for and trap a CAS error in a program?
One thing to remember, if you have a PPL program with an IFERR statement, there is an excellent chance that the next CAS command you use will crash your program.
Example: Code: EXPORT Demo_IFERR() You can force the error in the program above by pressing the ON key on the keyboard. If you do so, the crash/error happens when the "stddev" command is encountered. This is true for all CAS commands. Has caught me a few times now, and difficult to debug if you're not aware of this. I have written multiple substitute routines to get around the need for CAS commands as a result. |
|||
12-02-2018, 11:28 AM
Post: #7
|
|||
|
|||
RE: How to check for and trap a CAS error in a program?
(12-01-2018 03:41 PM)Albert Chan Wrote:Thanks Albert - length() is indeed the function that I'm after. I had previously tried DIM but it doesn't work for all expressions. I'd also tried SIZE with no luck, but overlooked length.(12-01-2018 02:48 PM)BruceH Wrote: separate #cas...#end bracketed function which calls part() with 1, 2, 3, .. etc until it fails and then return the max value And thanks also to Jacob for the warning - I had no idea I was going to open a can of worms. :-) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)