Setting up a public variable creates a default getter function, eg
`string[] public MyArray = ["E1", "3", "7"];`
Entering a value outside of the valid values of 0, 1, or 2 returns something like this:
call to setter_ex.MyArray errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
If I create a getter function I can add a 'requires' for error checking; eg.
`function getElement(uint _element) public view returns(string memory ArrayString){
require((_element >= 0) && (_element < MyArray.length),"error invalid entry");
return MyArray[_element];
}`
This returns the desired error message.
call to setter_ex.getElement errored: VM error: revert. revert The transaction has been reverted to the initial state. Reason provided by the contract: "error invalid entry". Debug the transaction to get more information.
Is it possible to do any kind of error checking in conjunction with the default getter to see if the entered value is valid that is similar to the 'requires'?