• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

custom exception class problem

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    reply
      Bookmark Topic Watch Topic
    • New Topic