throw an exception, all gas is consumed. What is the rationale for this design decision?
All gas is consumed because the EVM essentially only has 1 exception: Out of Gas.
Note also how "exception" in the EVM, is different from other languages. For example, there is no divide by zero exception in the EVM (though Solidity 0.4+ will generate an exception for this). Assuming valid EVM code, there are no exceptions except for Out of Gas.
Since there's only an Out of Gas exception, these other errors were made to behave as Out of Gas. This is relatively consistent with some Ethereum design principles of generalization and minimizing complexity. In other words, when implementing the behavior of stack underflow, invalid JUMP, and invalid opcode, it's simpler and easier for the protocol to reuse the implementation and behavior of Out of Gas.
Other answers have explained how Solidity compiles
throw to an invalid JUMP. (Serpent instead uses an invalid opcode, and calls it
invalid instead of
EDIT: The Byzantium release includes EIP 140, a new opcode named
REVERT in the EVM that:
provides a way to stop execution and revert state changes, without consuming all provided gas and with the ability to return a reason.
throw instruction gets compiled to an invalid JUMP instruction (i.e. a jump to an invalid location).
The section 9.4.2 of the Yellow Paper explains how exceptional halting works, in chapter 8 it explains that no gas is refunded in this case.
In chapter 8 it states:
Just as with contract creation, if the execution halts in an exceptional fashion (i.e. due to an exhausted gas supply, stack underflow, invalid jump destination or invalid instruction), then no gas is refunded to the caller and the state is reverted to the point immediately prior to balance transfer (i.e. σ).
And referring back to chapter 7:
If such an exception does not occur, then the remaining gas is refunded to the originator and the now-altered state is allowed to persist.
As to why it has been decided this way I have no information about.
In part I believe this was a security decision to ensure spamming the network with bogus transactions cost the sender gas. For instance, if gas was refunded after a throw, a malicious actor could create a contract that consumed some gas and then would throw. That actor could then send one or many transactions with a high gas price and a lot of gas, making their transactions take priority under default miner terms. Their transactions could take up all the gas in each block so no other transactions could go through, and if the gas was returned to them, they could do this for free indefinitely. With gas being consumed, this would cost them a good deal of ether.
throw instruction is a EVM hack that reverts all changes made by current contract execution. It exploits exceptional termination of EVM which also consumes all gas.