• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help: unreported exception java.io.IOException; must be caught or declared to be thrown
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help: unreported exception java.io.IOException; must be caught or declared to be thrown


  • Subject: Re: Help: unreported exception java.io.IOException; must be caught or declared to be thrown
  • From: Art Isbell <email@hidden>
  • Date: Mon, 3 Mar 2003 09:16:44 -1000

On Monday, March 3, 2003, at 02:24  AM, Andre Olivier wrote:

I want to display random files from the basePath given below.  The code
was in WO4.5 and I have tried to convert it to WO5.1.  I recieve above
error when compiling.  What does this mean?

     public NSData randomImage()
     {
         String filename = basePath;
         File file = new File( filename );
    -->  return new NSData(file);
     }

I believe this is really a Java, not WO issue.

The Java compiler is very strict in many ways. One of which is enforcing exception catching. If a method declares that it throws an exception and the code in which this method is invoked doesn't deal with the possibility of an exception being thrown, the compiler will complain that the exception "must be caught or declared to be thrown". Because the NSData(File) construction is documented to throw a java.io.IOException, its invocation must be in a "try" block or the method in which it is invoked, randomImage(), must declare that it "throws java.io.IOException". So you must implement one of these options.

By the way, the NSData(File) constructor is deprecated in WO 5.2, so you should check whether it is deprecated in WO 5.1. You should avoid using deprecated API whenever possible because it will likely not be supported in some future release which would likely result in your app crashing when run under that WO version. The Java compiler supports a handy -deprecated flag that prints a warning when deprecated API is encountered. This flag can be turned on in Project Builder. But various versions of PB support this in different ways, so you'll need to poke around in your version to figure out how it's done. Especially for code being ported, taking advantage of this flag is worthwhile.

Art
http://homepage.mac.com/aisbell/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Help: unreported exception java.io.IOException; must be caught or declared to be thrown
      • From: Andre Olivier <email@hidden>
References: 
 >Help: unreported exception java.io.IOException; must be caught or declared to be thrown (From: Andre Olivier <email@hidden>)

  • Prev by Date: Re: Can WOText Generate HTML Automatically On Save?
  • Next by Date: Re: 5.2 Not Responding
  • Previous by thread: Help: unreported exception java.io.IOException; must be caught or declared to be thrown
  • Next by thread: Re: Help: unreported exception java.io.IOException; must be caught or declared to be thrown
  • Index(es):
    • Date
    • Thread