It is legal Java code.
First part for the usage of Exception
in throws
declaration.
It should seldom be written in production code, before it suggests that the method could throw absolutely any checked exception, which is quite uncommon.
But it is currently used in Junit tests. The aim of a test function is to test one single feature, and should be as simple as possible because it is expected to not contain logic errors. So it is common to write the test as:
@Test
public void testFeature() throws Exception {
//actual test that can call any function declaring checked exception
}
Here this just means that you do not want to worry for possible exception declared in functions used in the test body.
But your code declares Exception in addition to other exception (sub-)classes. That is useless because all exception classes are subclasses of Exception
, thus IOException
and FileNotFoundException
are Exception
s.
So even if legal, this does not make sense: if you put Exception
in throws
declaration, you should remove all other exception classes because they are already contained in the Exception
declaration.