Does Java have any syntax for managing exceptions that might be thrown when declaring and initializing a class’s member variable?
public class MyClass
{
// Doesn't compile because constructor can throw IOException
private static MyFileWriter x = new MyFileWriter("foo.txt");
...
}
Or do such initializations always have to be moved into a method where we can declare throws IOException or wrap the initialization in a try-catch block?
Use a static initialization block