On May 14, 1:07 pm, miga <[email protected]> wrote:
> On May 14, 6:59 am, "* ^ *" <[email protected]> wrote:
>
> > I cannot seem to propagate the throws clause up the calling method.
> > Why?
>
> > The relevant code fragments are as below:
> > class WorldCupCountries{
> >     public WorldCupCountries() throws URISyntaxException{
> >         doSelectionNDisplay();
> >     }
> >     private void doSelectionNDisplay() throws URISyntaxException{
> >         URL dirURL=getClass().getResource(path);
> >         File dir=new File(dirURL.toURI());
> >     }
>
> > }
>
> > public class Main {
> >     public static void main(String[] args) throws URISyntaxException{
> >         SwingUtilities.invokeLater(new Runnable(){
> >             public void run() {
> > // Next line is the source of the error.
> >                 new WorldCupCountries();
> >             }
> >         });
> >     }
>
> > }
>
> > Exception thrown: Exception in thread "AWT-EventQueue-0"
> > java.lang.RuntimeException: Uncompilable source code - unreported
> > exception java.net.URISyntaxException; must be caught or declared to
> > be thrown.
> > But I have declared it should be thrown by main(). All input is
> > greatly appreciated. Thank you.
>
> You have thrown it, but you never have caught it. That's why finally
> it is the java runtime machine which throws it.
> See here the graphics, very explicitly (don't bother the text, it is
> in French).
>
> http://www.commentcamarche.net/contents/java/javaexc.php3
Thank you for your input and provided link. But, I an still not
clear.
I include a somewhat similar code below, but this one runs:
public class CopyTextFile {
    // main() just specify IOException. But NetBeans compiles and run.
No complaint.
    public static void main(String args[]) throws IOException {
        copyFile(inFile, outFile);
    }

    public static void copyFile(File fromFile, File toFile) throws
IOException {
        // Code that might throw an IOException.
        BufferedReader reader = new BufferedReader(new FileReader
(fromFile));
        BufferedWriter writer = new BufferedWriter(new FileWriter
(toFile));
    }
}

In both examples, main() specify a checked exception. But in the
previous example, NetBeans will not compile nor run. In this example,
compiles and runs. Why?

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to