Originally posted by: torpid
Originally posted by: jm20
Is this an example of good coding for exception handling ? or should I put the try catch statement in the main method and do them individually.
No. First off your exception message does not contain any useful information. If this were a big project even the developer would have no idea what it means without looking over the stack trace and line numbers.
Secondly, are you sure you are supposed to swallow the exception and not throw it?
Thirdly, you should not be setting the private fields to the value until AFTER you check its validity, and should not continue setting them if they are invalud. This does depend on what the theoretical use of the employee object is, but in general you should adhere to that, unless the assignment says otherwise.
Fourth, I'm not sure why you refactored the check out of the function, but it makes no sense to call it "getException" since that implies an accessor and not a function call, AND because it does not describe what the function is actually doing, which is validating the input.
Fifth, the name of the exception is too vague. You should consider using something like EmployeeInvalidWageException, and your exception probably should have a private field containing the hourly wage, in addition to the standard "message" that an exception ought to have.