---------- Forwarded message ---------- From: JKid314159 <[email protected]> Date: 2009/8/2 Subject: [java programming] Lab1007hw To: [email protected]
--- On *Sat, 8/1/09, miga <[email protected]>* wrote: > > a) The exception is now declared without constructor or other in it. If you don't put anything in the exception, then is it reasonable to extend the ArithmeticException? At least you may want to override the message returned by the exception, this is where the toString method is useful. ------------------------------------------------------------------------------------------------------------------ aa)At first I converted the integer back to a String. But now I understand the toString to override the message. So toString will return a message String. To do this, I write the method inside of the SpecificExceptionCreated class. I make the call in the catch block as such: SpecificExceptionCreated.toString(); Error message says can not call non-static method toString from static class? Here is the code: class SpecificExceptionCreated extends ArithmeticException{ public String toString{ String stringTemp = "message here"; return stringTemp; }//end toString() }//end SpecificExceptionCreated maybe I have to put in separate file and make static call? ------------------------------------------------------------------------------------------------------------------ > > b) I have caught the number format exception when the value entered is not a number. > I placed the parse inside of try block so format will throw runtime exception. > Then used if/else block for conditions of negative and zero? This is the step where you put the size inside a try/catch block in order to catch your own negative exception In the try block: 1 - you define the size 2 - you assert it positive ------------------------------------------------------------------------------------------------------------------ bb) Suppose to run program without assertions? ------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------ cc) I created two separate exception classes, one for negative numbers and the other for numbers equal to zero. This results in two conditions in the if/else block which throws to the catch statement on that particular exception. So each exception will have toString() method with each message? Send message back to catch block and put into pane or out. ------------------------------------------------------------------------------------------------------------------ Respects, *JKid314159* http://existentialists.blogspot.com/ <http://groups.google.com/group/existentialist-reading-circle?hl=en> -- Cheers, Michèle --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
