hi im trying to write a program that will create a class to store info on books (title, author, number of pages and price) and that will trow a custom exception when the price entered for a book is higher than 10 cents per page. I got the class working but i cant figure out how to throw the exception any help would be appreciated.
Do you really want to throw an exception? Or just test the price and throw up a messagebox alerting them that the price is not acceptable? And/or allow them to to confirm the price is what they entered?
Assuming you really don't want to throw an exception ... you would want to a test at the top of your method with an if/else (before you commit he data) ... and if its above your 10 cents a page, throw up a messagebox and let the user respond. If they confirm its the right price, commit the data ... if the user confirms its not the right price, then exit the method without committing the data.
I would have the method return a boolean (true/false) response to the calling code, so that code knows whether to clear the data that they just tried to commit ... or just leave it for modification if it wasn't committed.
If you gave us some code to visualize, we could give a better example.