有没有办法 return 一个函数为 false 并且仍然执行代码直到它恢复,eq: function owner() { owner = 0x0;恢复(); }
Is there a way to return a function as false and still execute code untill it reverts, eq: function owner() { owner = 0x0; revert(); }
因此将 revert() 或 throw 放在函数的末尾只会阻止任何代码的执行,我正在寻找一种聪明的方法来避免这种情况,无论是通过外部调用、委托调用还是其他任何方式,所以:
function thiss()
{
owner = 0x0...;
throw; //gives error, no changes whatsoever - what I want is to see changes and then "throw"...
}
一种方法是使用 event
。您可以发出事件,然后 return 函数。您可以通过查看交易收据中的 logs
字段来了解错误。
event ErrorLog(string msg);
function this() public {
Owner = 0x583031D1113aD414F02576BD6afaBfb302140225;
emit ErrorLog("Error in function this");
return;
}
因此将 revert() 或 throw 放在函数的末尾只会阻止任何代码的执行,我正在寻找一种聪明的方法来避免这种情况,无论是通过外部调用、委托调用还是其他任何方式,所以:
function thiss()
{
owner = 0x0...;
throw; //gives error, no changes whatsoever - what I want is to see changes and then "throw"...
}
一种方法是使用 event
。您可以发出事件,然后 return 函数。您可以通过查看交易收据中的 logs
字段来了解错误。
event ErrorLog(string msg);
function this() public {
Owner = 0x583031D1113aD414F02576BD6afaBfb302140225;
emit ErrorLog("Error in function this");
return;
}