Java: startingPath as "public static final" exception

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-04-10T15:55:50Z Indexed on 2010/04/10 16:03 UTC
Read the original article Hit count: 388

Filed under:
|
|
|
|

[Updated] Thanks to polygenelubricants's reply, the real problem is the exception from the method getCanonicalPath() because I cannot include try-catch-loop there.

$ cat StartingPath.java 
import java.util.*;
import java.io.*;

public class StartingPath {
 public static final String startingPath = (new File(".")).getCanonicalPath();

 public static void main(String[] args){
  System.out.println(startingPath);
 }
}
$ javac StartingPath.java 
StartingPath.java:5: unreported exception java.io.IOException; must be caught or declared to be thrown
 public static final String startingPath = (new File(".")).getCanonicalPath();
                                                                           ^
1 error

© Stack Overflow or respective owner

Related posts about java

Related posts about scope