Templates (template metaprogramming) help to avoid exceptions. You can check invariants first and jump into efficient code.