I have been trying to run this code:
function seeError(address _token) public view returns (uint256) {
try IERC20(_token).decimals() {
return IERC20(_token).decimals();
} catch {
revert("Error occured");
}
}
Now, since I can input any address for the token, I want to revert in case there are no decimals returned, or basically, the ERC20 address is wrong. So I tried using try/catch for this since I am unable to get the data directly. Is there any way to get the result I want? Try/catch is working for external calls only, can it work for view
functions too?