Error handling improvements

Progress on #897. Not really done with everything I'd like to accomplish, but I think this part is ready and it would be nice to see it in 0.9.0.