I have the following piece of code:

function func() public returns (bool) {
    if (some condition on msg.sender) {
        do some stuff
        return true;

The compiler (0.4.24) does not issue any warning about this, even though not all execution paths return a value.

Of course, I could call revert() right at the beginning (with an opposite condition) and avoid this issue, but for internal coding-style considerations, I prefer it as shown above.

Now, I know that in C++ for example, a function can throw an exception instead of returning a value and everything remains "in tact". So I suppose that it might be the same here, but I still want to be sure that there is no potential for stack-corruption or something similar (due to the fact that nothing is pushed into the stack when the function terminates).

According to the docs, the revert opcode actually does return something.

But I'm not sure if the revert function does, and even if yes, it wouldn't necessarily be of the same type as in my function (bool in this case).

So... do I have anything to worry about here, or does the thrown exception "take care" of the returned value?

Thank you!

1 Answer 1


Typically revert will bubble-up and revert the whole transaction so you don't need to worry about incorrect return values - the whole transaction will fail. There is no way to catch this kind of exception and therefore no way to prevent it from happening if the code issues a revert.

There are some minor exceptions to this rule, namely delegatecall and similar functionalities. You can read more about this behaviour (and reverting in general) at: https://solidity.readthedocs.io/en/v0.4.24/control-structures.html#error-handling-assert-require-revert-and-exceptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.