即使try块实际上没有抛出任何异常,下面的代码也可以编译好.
public static void main(String[] args) {
try {}
catch (Exception e) {} // compiles ok
}
Run Code Online (Sandbox Code Playgroud)
但是如果使用Exception的子类替换catch,则代码将无法编译.
public static void main(String[] args) {
try {}
catch (IOException e) {} // won't compile.
}
Run Code Online (Sandbox Code Playgroud)
编译器错误是:IOException的无法访问的catch块.永远不会从try语句主体抛出此异常.
当异常和IOException都被检查异常时,为什么会出现这种情况?我正在使用Java 7.
bash脚本新手.在bash脚本的开头,初始化变量
silent_install=true
Run Code Online (Sandbox Code Playgroud)
然后在脚本中以下面两种方式使用此变量
if [ -z "$silent_install" ]; then
Run Code Online (Sandbox Code Playgroud)
和
if [ -z ${silent_install} ]; then
Run Code Online (Sandbox Code Playgroud)
这2个用法有什么区别?
ExtJS 新手。我有以下代码。
var comp;
console.log('comp is - ' + comp);
comp = Ext.create('Ext.Component', {
listeners : {
beforedestroy : function(comp) {
console.log('beforedestroy .. ');
},
destroy : function(comp) {
console.log('destroy .. ');
}
}
});
console.log('comp is - ' + comp);
console.log('comp id is - ' + comp.getId());
comp.destroy();
console.log('comp is - ' + comp);
console.log('comp id is - ' + comp.getId());
Run Code Online (Sandbox Code Playgroud)
chrome 的控制台输出是
comp is - undefined
comp is - [object Object]
comp id is - component-1009
beforedestroy .. …
Run Code Online (Sandbox Code Playgroud)