英文:
Why is the catch Exception always called e
问题
例如:
尝试 {
int n = scan.nextInt();
System.out.println("\n你输入的数字是:" + n);
} catch (Exception e) {
System.out.println("你输入了一个无效的值。");
}
似乎每个带有 `catch` 语句的程序中都将异常称为 `Exception`,这是一种不成文的规则吗?
英文:
For example:
try {
int n = scan.nextInt();
System.out.println("\nYour number is: "+n);
}catch(Exception e) {
System.out.println("You entered a value thats not valid.");
It seems like every program with a catch
statement in it has the Exception
called e
. Is this like an unwritten rule or something?
答案1
得分: 2
因为惯例。给事物命名很难。拥有共同的词汇有助于理解彼此的代码。
英文:
Because of conventions. Naming things is hard. Having a common vocabulary helps understanding each other's code.
答案2
得分: 2
在我看来,没有这样的规定,只是更短而已...这取决于你和你的编程习惯。
英文:
IMHO, no there is no such rule, it is just shorter like that... It is up to you and to your programming habit.
答案3
得分: 2
驼峰命名法通常在Java中使用的原因相同,你可以使用蛇形命名法,但不建议,因为出于某种原因会使你的代码难以阅读。
String helloWorld;
String hello_world; //看起来有点奇怪,不是吗?
英文:
The same reason why camelCase is generally used in java for naming, you can use snake_case but it's not recommended and makes your code harder to read for whatever reason.
String helloWorld;
String hello_world;//seems a bit off doesn't it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论