11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 25: Handling Errors — Exceptions 335match the int, so it’s skipped. The next catch phrase matches the int exactly,so control stops there. The final catch phrase, which would catch any objectthrown, is skipped because a matching catch phrase was already found.What Kinds of Things Can I Throw?The thing following the throw keyword is actually an expression that createsan object of some kind. In the examples so far, I’ve thrown an int and a stringobject, but throw can handle any type of object. This means that you canthrow almost as much information as you want. Consider the following updateto the factorial program, CustomExceptionClass://// CustomExceptionClass - demonstrate exceptions using// a factorial function//#include #include #include #include using namespace std;// Exception - generic exception handling classclass Exception{public:Exception(char* pMsg, int n, char* pFile, int nLine): msg(pMsg), errorValue(n), file(pFile), lineNum(nLine){}virtual string display(){ostringstream out;out

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!