Based on experienced mentors it seems like throw mechanism is suggested here. I guess catch mechanism does not exist for throw: https://ethereum.stackexchange.com/a/2512/4575.
Based on that I have a problem: First I have to check some condition which might take high gas value. If the condition is failed throw will take place. So if condition fails, I want to pay back the money to the client. Otherwise, money should pay back to the cluster.
[Q] If condition fails, throw will take place. Since throw terminates the code, there is no way for me to catch the reverted version, and apply 1 line of code to payback the money to client. Is there any alternative solution to handle this issue?
Please note that condition will change state. So I have to do throw if there is condition fails.
function payMeBack() {
if(require(<some condition>)) //if condition is wrong throw take place and never JUMPS to else side.
if(!client.send(gainedWei)) throw;
else
if(!cluster.send(gainedWei)) throw;
gainedWei = 0;
client.success = 1;
}
Thank you for your valuable time and help.
pay()first the money will be dropped from clients account. On the payMeBack(), condition check that for ex: does the item successfully delivered to the seller. If yes, gained money by the contract will be paid to the sellerseller.send(gainedWei). If no, it will pay back to the client as refundclient.send(gainedWei). Hope it is bit more clear. So mainly payMeBack also should decide who will gain the money seller or the client based on the conditions. @RobHitchens. – alper Apr 14 '17 at 06:54ifcondition is a function and my change some states, which will return true or false. The function may consume a lot of gas. So it may seem to just usethrowinstead ofif/elsesince reverting states by hand may consume additional gas usage. @Rob Hitchens – alper Sep 24 '17 at 04:09