throws clauses are simplified
See original GitHub issueCFR version
0.149-SNAPSHOT (commit 254c677)
Compiler
javac 11.0.5
Description
throws
clauses are simplified, duplicate declared exceptions are omitted and generic types are reduced to their erasure type. While this results in functionally equivalent code, the difference can be detected using reflection.
Source:
class ThrowsClauseExact<E extends Exception> {
public void testThrow() throws Exception, E, E, RuntimeException, RuntimeException { }
public static void main(String... args) throws Exception {
System.out.println(ThrowsClauseExact.class.getMethod("testThrow").getExceptionTypes().length);
}
}
Decompiled output:
class ThrowsClauseExact<E extends Exception> {
ThrowsClauseExact() {
}
public void testThrow() throws RuntimeException, Exception {
}
public static void main(String ... arrstring) throws Exception {
System.out.println(ThrowsClauseExact.class.getMethod("testThrow", new Class[0]).getExceptionTypes().length);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Throws Keyword in Java | Throws Clause - Scientech Easy
Throws clause consists of throws keyword followed by a comma-separated by the list of all exceptions thrown by that method. Throws Keyword in...
Read more >What is the point in throws clause? - Stack Overflow
The throws clause says that a method is allowed to throw certain exceptions. It sets out the contract that the method has with...
Read more >throw and throws in Java - GeeksforGeeks
The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw...
Read more >Throw and Throws in Java - C# Corner
This article has explained the throw statement and the throws clause in Java. These keywords are very important in exception handling in ...
Read more >Java Throws Keyword in Exception handling - BeginnersBook
The throws keyword is used to handle checked exceptions. As we learned in the previous article that exceptions are of two types: checked...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Lol. I had to.
ThrowsClauseExact2.class.txt
@ItzSomebody - Chris, you might find that one amusing in fernflower.
Did you try decompiling the above in idea/fernflower? 😃 Not so much a side effect in the class file, rather one left for the unwary reader, or the immediate recompiler - It’s a bit silly, but it’s a fun trap to leave…