Why is it expensive to use objects for the exception?

a) Exception object is created only if an error actually happens
b) Because of execution time
c) Memory space involved in creating an exception object
d) Because of time and space

1 thought on “Why is it expensive to use objects for the exception?”

  1. a
    Explanation: If an error occurs in the program, then only exception object is created otherwise, It will not be created. since throwing an exception triggers a bunch of actions during the stack unrolling, like invoking the the destructor of all the objects that has been created up to the point in which we are able to catch the exception, and invoking the destructor methods can imply flushing streams and freeing memory which can be expensive as well. Therefore, it’s expensive to use in the program.

Leave a Comment