Verify datatypes with try catch

I’m trying to use try catch to verify that the datatypes that were input by the user match what is allowed.

As in the input dialog asks the user for their phone number - the try catch will make sure that it is an integer.

I’m having issues with the CATCH portion. I have try → user inputs their name and phone number. Any advise on the catch to make sure the datatypes match?

Where is the user inputting the values?

in the try

Users don’t enter things into a try. Are they filling out and submitting a web form? Are you popping up an input dialog?

popping up an input dialog - the instructions of the assignment are - using a try catch block - ask the user for their variables and verify the datatypes match

Hope this helps in what you’re trying to achieve.

TryCatchExample.xaml (13.9 KB)

Note: when you’re converting to Integer, make sure you’re using int64 and not int32.
Int32’s value capacity is -2147483648 to +2147483647. So if your number is like 6825556666, int32 will fail.

It does help but not in the user input part. I have to have a user input the number and then check if the number is the correct datatype as part of the assignment. The assignment says - ‘using a try catch block - ask user for their variables and verify the datatypes match’

I think this is what you need then. Whatever datatype you’re expecting, the input dialog will try to convert to that, otherwise throws exception.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.