Link to home
Start Free TrialLog in
Avatar of mb650cd
mb650cd

asked on

Exception Handling in C++

I have to write an exception class that will output a different message for each different situation, how do I even start writing an exception class. Please help. Thanks

mb
Avatar of PerlChaser
PerlChaser

You can create an exception class by simply using a message in it.  For example, if you were checking for invalid digits, you would use

InvalidDigit::InvalidDigit()
{ msg = "That is not a valid digit.\n"; }

Then, in your code you could have

if(!(isdigit(n)))
  throw InvalidDigit();

Hope this helps!
~PerlChaser~
ASKER CERTIFIED SOLUTION
Avatar of n_fortynine
n_fortynine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mb650cd,

Please wrap up this question; you have had sufficient time to evaluate these comments.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: n_fortynine

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer