*
The moose likes Beginning Java and the fly likes Modify by throwing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Modify by throwing" Watch "Modify by throwing" New topic
Author

Modify by throwing

Jeffery Miller
Greenhorn

Joined: Jan 16, 2008
Posts: 2
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.


Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
"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
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modify by throwing
 
Similar Threads
Help with Value Returning Methods
Printing
cannot resolve symbol
Circle program errors
Runtime and compile-time ?