Improve message when there is an error in a value function
When an exception gets raised inside a value function Kwant needs to exit with an error. There's nothing we can do about that, since it's the user who is responsible for the value function.
The error message could be improved, however. Right now it's a long and intimidating traceback that looks like a bug in Kwant. The part of the traceback that is relevant to the user appears only at the bottom.
This could be turned into a message that (ideally) clearly states that there is a problem with a value function when called with this-and-that arguments, and then shows only the relevant part of the traceback.
This should be doable by adding try
blocks to kwant.builder.FiniteSystem.hamiltonian()
and kwant.builder.InfiniteSystem.hamiltonian()
.