Handle errors in external calls

As we discussed earlier, solidity has some low-level call methods: address.call(), address.callcode(), address.delegatecall(), and address.send(). These methods only return false when the call encounters an exception. So handling errors in external calls is very important in contracts, as shown in the following code snippet:

// good
if(!contractAddress.send(100)) {
// handle error
}
contractAddress.send(20);//don't do this
contractAddress.call.value(55)(); // this is doubly dangerous, as it will forward all remaining gas and doesn't check for result
contractAddress.call.value(50)(bytes4(sha3("withdraw()"))); // if withdraw throws an exception, the raw call() will only return false and transaction will NOT be reverted
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.182.107