Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

custom exception class problem

 
Albert Park
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 28
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 28
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic