• 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

Modify by throwing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need some help to modify the perimeter method in the following program so it will throw an Exception object. Guidence or an example would be appriciated.


 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ouch". Yes, it will work, but because it is a checked Exception it requires a "throws" or a "try-catch."
Go into your Java folder on your PC, and explore it until you find a file called src.zip. Unzip that, find a method which throws an Exception, and examine that.
Find the java folder, in that the awt folder, in that the Color class, then inspect its constructors. See how they deal with Exceptions. Have a look at the Java Tutorial here.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really ought to learn to read. I see you already have a try-catch, but not a "throws." You ought not to catch "Exception," but a subclass on Exception.
When I said "method which throws Exceptions" the constructor I quoted is a similar example.
 
reply
    Bookmark Topic Watch Topic
  • New Topic