Why do you need parentheses in catch blocks in Java?
•
Java
In Java, if we have to execute a statement after if, or if we don't have to execute a statement for parentheses We can write:
if(condition) executeSingleStatement();
or
for(init;condition;incr) executeSingleStatement();
But in the case of catch blocks, why can't we omit parentheses? Why is this impossible?
catch(Exception e) e.printStackTrace();
Because in most cases, we have only one statement in the catch block, which is e.printstacktrace()
Solution
This is not a possible or impossible problem This is just a language (grammar) design decision
The Java language parser has several implementations You can modify the parser source in less than a day and allow catch statements without parentheses
http://www.google.com/search?q=java +parser
Also note the Java language grammar
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码