On Aug 1, 1:53 am, JKid314159 <[email protected]> wrote:
> Dear Java Programmer:
>  
> //This iexception throws non-negative value
> class MyOwnNegativeValueEnteredException extends ArithmeticException {
>     public MyOwnNegativeValueEnteredException(){
>         ArithmeticException();
>     }//constructor
>
> }//   
You do not need any constructor, it will call automatically the super
constructor as you extend it. Now you need perhaps to overwrite its
toString method to return the message you want to be returned when
hitting the exception. If you recall well, we have already used the
toString method in another lab (inheritance or so).

Then you may use this exception for the size by throwing it if size is
negative, idem for the zero value exception.You may also used it in a
JOptionPane. Just remember that exceptions are caught in a logical
order, so don't try to catch any arythmetic exception unless you are
already sure the number passed is really a number.


> I am trying to call the ArithmeticException and make it output a string such 
> as "Non-negative value."
So, put it in the toString method.

>  
> I just can't grab ArithmeticException in a custom way.
Next, for example, you may throw it for size if size is negative. Use
a try/catch block for this.

And you may catch it an use it in a JOptionPanev show message dialog

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to