Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific checked exceptions.

  • Someone reading your API code has no easy way to find out what checked exceptions might actually be thrown or propagated by the method.

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific checked exceptions.

  • Someone reading your API code has no easy way to find out what checked exceptions might actually be thrown or propagated by the method.

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific checked exceptions.

  • Someone reading your API code has no easy way to find out what checked exceptions might actually be thrown or propagated by the method.

added 17 characters in body
Source Link
Stephen C
  • 25.4k
  • 6
  • 67
  • 90

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific checked exceptions.

  • Someone programming againstreading your API code has no ideaeasy way to find out what checked exceptions might actually be thrown or propagated by the method.

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific exceptions.

  • Someone programming against your API has no idea what checked exceptions might actually be thrown or propagated by the method.

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific checked exceptions.

  • Someone reading your API code has no easy way to find out what checked exceptions might actually be thrown or propagated by the method.

Source Link
Stephen C
  • 25.4k
  • 6
  • 67
  • 90

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on StackOverflow:

The short version is that if you declare a method as throws Exception, any code that calls that method must either catch (Exception ...) or have its own throws Exception clause. If you do this consequences are as follows:

  • You have nullified the compiler's ability to tell you when you haven't handle specific exceptions.

  • Someone programming against your API has no idea what checked exceptions might actually be thrown or propagated by the method.