Hello, I'm pretty new to this and I'm trying to learn exception handling right now. This is part of an assignment I'm working on but the problem I'm running into is with the second prompt. When the user enters a time, if it is a string it should throw an exception, it does do this but when the loop starts again the string gets stored in the name variable which I don't want. Any thoughts or suggestions would be appreciated. Thank you.
I have tried blanking the name variable but that hasn't done anything. Every time it will ask the user for "The appointment time to be entered". I tried stepping through each line of code and the string that causes the error, it gets added to the name variable once it loops back and starts over again.
If the time is invalid, throw the Exception. Don't try to catch it.
The problem you have is that Exceptions are designed to show that an error has occurred and the method cannot complete. They will only work if you have several methods. Trying to throw an Exception and catch it in the same method is simply an ineffieicnt way to implement an if-else. Don't do it.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com