At the University I went to, that happened. The professor would put something we had never covered in class on the final, to test our synthesis and extrapolation. Part of engineering is creativity, not just parroting back the exact thing taught.
It happened in lower grades, too, but it didn't count, or at least didn't count heavily, if it was brand new material. If it was material that should have been covered in a previous class or grade, it was fair game.
One consolation is that if a question is something that was never covered at all, the whole class is in the same boat.