43: Try and Catch
function sendMoney(address _to, uint256 _amount) public payable {
try {
require(_amount <= 5 ether);
_to.transfer(_amount);
}
catch (bytes32 err) {
revert("Only 5 ether can be sent at a time");
}
}function sendMoney(address _to, uint256 _amount) public payable {
try {
require(_to != msg.sender);
_to.transfer(_amount);
}
catch (bytes32 err) {
revert("Sender and receiver cannot be the same address");
}
}Last updated