Accessing an element that does not exist with the subscript operator results in undefined behavior. You may get a segfault if you are lucky, or if you are unlucky you may get a garbage value. You seem not to understand how to use exceptions - why are you trying to throw and catch a nonexistant element?