简体   繁体   English

InterruptedException e

[英]InterruptedException e

I'm reading about InterruptedException because I'm dealing with threads, and I'm wondering is the catch (InterruptedException e) a special case because there is an e there? 我正在阅读有关InterruptedException因为我正在处理线程,所以我想知道catch (InterruptedException e)是一种特殊情况,因为那里有e吗?

I've seen ie , but unfortunately I can't seem to find any webpage that tells me what the letters after InterruptedException do. 我看过ie ,但是很遗憾,我似乎找不到任何网页告诉我InterruptedException之后的字母是做什么的。

Are there different InterruptedException s? 有不同的InterruptedException吗?

No, they're not. 不,他们不是。 The e or ie after InterruptedException is just the name of the variable where the exception raised will be caught. InterruptedException之后的eie只是捕获引发的异常的变量的名称。

This piece of code: 这段代码:

try {
} catch (InterruptedException e) {
    e.printStackTrace();
}

And

try {
} catch (InterruptedException ie) {
    ie.printStackTrace();
}

Are basically the same. 基本上是一样的。 The only difference is the name of the variable, the former declares it as e while the latter declares it as ie . 唯一的区别是变量的名称,前者将其声明为e而后者将其声明为ie

It is irrelevant. 这无关紧要。 It is just a variable name. 它只是一个变量名。 You can name the exception anything. 您可以为异常命名。

catch(Exception someVariableNameYouChoose)

That is just an name for your exception object. 那只是您的异常对象的名称。 You can have "kokoobananas" in place of "e" :). 您可以用“ kokoobananas”代替“ e” :)。 Just make sure you use kokoobananas.printStackTrace() 只要确保您使用kokoobananas.printStackTrace()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM