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.