Is there a way to catch this error.

For example, myprgm takes 5 arguments. In time i wil forget how many, so i am trying to catch errors "to few/many arguments". So if this error accures, program would display number of arguments needed instead of exiting.

I tried with Try Endtry, but it doesn't work.
Hi timijan,

What calculator are you trying to do this on? It sounds to me like its either the Nspire or TI89/92/v200 since you mention the Try Endtry but clarification would help.

If you could post some of your code as well that would be helpful so we know more about what you are trying to do and can be more specific with out assistance.
You are correct, i am using ti89.

I have program with 5 arguments myprgm(a1,,a2,a3,a4,a5)
Lets say i forget there are five and i enter myprgm(a1,a2,a3,a4). Result of this is an error "Too few arguments" and program crashes.
I would like to catch this error and display msg: "this prgm takes 5 arguments".

I think this is not possible in ti-basic, but it doesn't hurt to ask anyway
On TI-89, use:

:Try
: myprgm(args)
:Else
: If errornum=930 Then
: <if too few arguments>
: ElseIf errornum=940 Then
: <if too many arguments>
: Else
: PassErr © Don't catch any other errors
: EndIf
:EndTry

That's if you're calling myprgm from another program—a program can't error-trap its own arguments because the check happens before that program even has a chance to run.

If you just want a way to remember how to call the program, one workaround is to stick a single comment line at the very beginning of the program listing the arguments. Then it will be listed as a help string when you go to CATALOG and press F4.
Travis wrote:

That's if you're calling myprgm from another program—a program can't error-trap its own arguments because the check happens before that program even has a chance to run.

If you just want a way to remember how to call the program, one workaround is to stick a single comment line at the very beginning of the program listing the arguments. Then it will be listed as a help string when you go to CATALOG and press F4.


Thanks. I thought that wasn't possible.

Your first solution would be great is some other scenario, but in my case i would have to do something like this:

My input on home screen would be:
Try_program("my_function(arguments)")

Prgm Try_program(x)
:Try
: Expr(x)
:Else
: If errornum=930 Then
: <if too few arguments>
: ElseIf errornum=940 Then
: <if too many arguments>
: Else
: PassErr © Don't catch any other errors
: EndIf
:EndTry

And then write some additional code for displaying help-notes, regardless on which my_function was called. To messy, both input and the code.
I will probably just store my help in notes or write it on a paper and stick it on the back cover Smile

Thanks for your answer again.
I found a great solution. I can put all my arguments in a list, which is interpreted as 1 argument.
I will now change all my programs to something like this:

myprgm(a1,a2,...,an) to myprgm({a1,a2,...,an})

I can then simply check the list dimension:

:Prgm myprgm(my_list_of_arguments)

:If dim(my_list_of_arguments)≠'number of arguments needed for myprgm' Then
:Disp "some help text"
:Endif
:myprg code

:End prgm
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement