Why should various cases be converted to const values?
–
tesicgApr 7 '14 at 11:42

2

@tesicg It is a point for consideration, as the name of the constant is more descriptive then the string values. If this value is to be used at multiple locations, then it is easier to refractor the code at a later point. I have updated the answer to include a sample.
–
KamiApr 7 '14 at 12:24

You are using the exception as a way to break out of the for loop. This is exactly what the break statement is for. Instead, you create a new Exception, which must populate the stack trace, and then the code starts to unwind the stack looking for the closest matching catch. This is an expensive process for something that is very basic. This could be replaced with:

In addition, you are throwing the base class Exception. This means that the most specific catch you can write is for the base class. This will catch all exceptions, including things like StackOverflowException and OutOfMemoryException. Your code will then try to continue on with no knowledge that these much more serious exceptions were swallowed up into a log message.

When you throw an exception in your code, it should be a sub-class of Exception that is as specific as you can be. This may be a predefined exception of an exception class you explicitly declare. By doing this, you can use the type system to handle different types of exceptions differently and not catch the exceptions you don't mean to handle.

also, he is misusing the phrase "fatal error". A fatal error occurs when the entire program fails, but his catch block exists only in the CheckPay() function. It would be more accurate to print something along the lines of "error in CheckPay()"
–
Red AlertApr 7 '14 at 18:08