c++ - Should I Return A Value Or Throw An Exeption....? -
c++ - Should I Return A Value Or Throw An Exeption....? -
i writing generic class of template t.
it has fellow member function as
t findelement (t data1) { tree<t> *tree=search (data1,treetop); if (tree==null) cout<<"\n element not found \n "'; else // usefult part of code returns info of type t (generic) } now if 1st status true should throw exception...??
will tamper functions homecoming type. little explanation on how exception works helpful.
whether or not throw exception subjective question depends on situation , coding style.
in general folk throw exception in unusual circumstances - if expect many searches searches homecoming no result perhaps returning special or specially formed element idea, if should or never happens under normal circumstances exception judged appropriate developers.
regarding homecoming type: when function throws there no homecoming type function never returns, instead programme resumes on first line of grab in calling context.
c++ function exception-handling return-value
Comments
Post a Comment