Code has been added to clipboard!
Solidity Error Handling Example
Example
pragma solidity ^0.4.0;
contract TheSharer {
function sendHalfSum(address addrTo) payable returns (uint balance) {
require(msg.value % 2 == 0); // Allow even numbers only
uint balanceBefore = this.balance;
addrTo.transfer(msg.value / 2);
// Because transfer will throw an exception if it fails and
// is unable to call back here, we should have no way to
// = have half of all the money still.
assert(this.balance == balanceBefore - msg.value / 2);
return this.balance;
}
}