1) You're missing a } in the constructor. 2) The UnAcceptableNumberException takes only one integer, not two. 3) The AbsoluteNumberException throwing misses the () and the integer argument. 4) The class is actually called AbsoluteException 5) Where does newBig come from in getBig? 6) setBig misses the newBig parameter 7) toString() misses the return statement: return s; 8) You mistyped both JOptionPane and showMessageDialog in the exception constructors. Actually, you mistyped them EVERYWHERE. 9) The import statement has to go at the top of the file. Only the package statement, comments, whitespace and other import statements can come before import statements. 10) You haven't declared bigNo and smallNo. 11) nt is declared inside the try block, and is not available outside of it.
I haven't even looked at style or anything, this is just syntax. Seriously, please try compiling code before you post it. An IDE such as Eclipse would have shown you all these errors and suggestions on how to fix them.
Try write code one bug at a time -- i.e., write the smallest possible program that will compile; fix any compiler errors; test it; and only then should you add more. That way you'll know that any error has to do with the last one or two lines that you typed.
Now, even if you get this to compile, it is still an abomination before man and God. Take that JOptionPane stuff OUT OF THE EXCEPTION CONSTRUCTORS, and move it into those empty "catch" blocks! Exceptions are for reporting errors in code; catch blocks are for handling them (and one part of "handling" is "reporting to the user.") Never, never print anything or especially put up a dialog box inside the constructor of an exception class, and never, never write an empty catch block!
Originally posted by Ernest Friedman-Hill: Never, never print anything or especially put up a dialog box inside the constructor of an exception class, and never, never write an empty catch block!
Agreed. An exception constructor should basically call one of the super constructors as much as possible, and set any local variables. As for the empty catch block, if you don't want to do anything meaningful, at least log the exception, e.g. by calling e.printStackTrace(). That way, you can at least open the application in a console and see what exceptions are being thrown.
Joined: Aug 20, 2007
hi ,everyone i did alot of amendment and changes to the program.
the program seem working fine without test class. however, i' m confuse whether what i have code is right? it's seem wrong to me, however there is a right ouput. after comparing the values..
my question is actually am i require to output the values in the BloodPressure class or just the exception class will do?
but i'm struck on how do i test whether my program works?
appriecate if anyone able to advice me on that. kind of confuse by my own codes.
p/s: the vaules enter will be assume either low or high.
these are the codes.
[ October 17, 2007: Message edited by: xiao sean ] [ October 17, 2007: Message edited by: xiao sean ]
author and iconoclast
You're still not using exceptions correctly. Call "checker" from the BloodPressure constructor. Take those print statements out of the Exception constructors and put them into the PressureException catch block. The idea is that code throws an exception to indicate that something is wrong, and some other code catches that exception and does something -- fix the problem, report it to the user, etc.