aspose file tools*
The moose likes Beginning Java and the fly likes custom exception class problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "custom exception class problem" Watch "custom exception class problem" New topic
Author

custom exception class problem

Albert Park
Greenhorn

Joined: Feb 01, 2012
Posts: 28
Hello again,
I am learning about exception and I can't figure out why Eclipse is giving me this message.

I have created an exception class extends Exception , a CircleWithException class to see if my exception works.
If I am doing it correctly, eclipse should recognize my exception class and should work, since InvalidRadiusException class is now a subclass of Exception.
Any help would be great.

Thanks in advance.

This is my exception class.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38405
    
  23
Which class has the setRadius method which actually declares that Exception?

I know you are only doing this as a “what happens if” exercise, which permits you to try anything short of deleting every file on your hard drive, but in real life you would do at least three things differently:-
  • 1: Not give the radius to the exception as a field.
  • 2: Not make that exception checked.
  • 3: Use java.lang.IllegalArgumentException instead.
  • Albert Park
    Greenhorn

    Joined: Feb 01, 2012
    Posts: 28
    Campbell Ritchie wrote:Which class has the setRadius method which actually declares that Exception?

    I know you are only doing this as a “what happens if” exercise, which permits you to try anything short of deleting every file on your hard drive, but in real life you would do at least three things differently:-
  • 1: Not give the radius to the exception as a field.
  • 2: Not make that exception checked.
  • 3: Use java.lang.IllegalArgumentException instead.


  • sorry about that, I fixed the code, but instead I get a red underline inside my constructor in CircleWithException class.
    Yes, if I just use IllegalArgumentException, it works fine.
    But the book wants me to create a custom exception to handle this.
    Albert Park
    Greenhorn

    Joined: Feb 01, 2012
    Posts: 28
    Campbell Ritchie wrote:Which class has the setRadius method which actually declares that Exception?

    I know you are only doing this as a “what happens if” exercise, which permits you to try anything short of deleting every file on your hard drive, but in real life you would do at least three things differently:-
  • 1: Not give the radius to the exception as a field.
  • 2: Not make that exception checked.
  • 3: Use java.lang.IllegalArgumentException instead.


  • ok. I followed your first two advice and it works.
    And yes, I got the correct compile error which made this work.

    Thank you for making me think
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: custom exception class problem