c++ - Exception thrown in handler functions -
i reading following text in applied c++ book.
can exceptions thrown within our handler functions? answer yes, error can indeed thrown. problem exception must in every exception specification may tranversed until exception caught. if not done, application call std::terminate(). large system, amounts adding exception specification every function , unless understand dynamics of application perfectly. important cath exceptions within destructor; otherwise, std::terminate() called in case.
in above text have following questions , need in understanding.
what author mean "exception must in every expection specification may traversed" ?
my understanding destructor cannot use exceptions. author mean catch exceptions within destructor.
request clarify simple examples
thanks time , help.
generally, exception specifications bad idea, because produces lot of refactoring , scale problems (the problems wich autor talks about) when modify specifications. case of java checked exceptions. c++ has no checked exceptions, problem exception specifications same, if want write uniform api.
in fact exception specifications deprecated since c++11. c++11 uses noexcept
specifier ensure function not throws exception. allows compiler optimizations, , of course provides guaranties user of function. if function doesn't have noexcept
specifier, can throw exception or not.
exceptions are, name says, exceptional. is, using try...catch
flow-control bad programming technique. if program designed, when exception thrown, means go very wrong. is, exceptional execution case. , exceptional execution event translates execution abort. why functions not have try..catch
blocks everywhere exception thrown.
Comments
Post a Comment