Most of the code I read out in the wild follow the precondition pattern if (condition) throw;
But this approach is cumbersome for clients to read. For example, with web3js
you would have to check if the full consumption of gas means that a throw happend or you ran out of gas. With Geth at least you can examine the callstack for an invalid jump
via debug.traceTransaction()
It seems much more appropiate to follow this approach:
if (condition)
{
ExceptionEvent();
return ERRCODE;
}
By doing that you are capable getting the exception right.
Since using throw
is so common in the codes I examined, what are possible drawbacks of my proposition, beside that you have to handle the error in all parts of the callstack correctly?