空 try 塊是 dead code 或者表示存在調試代碼。
空 try 塊沒有任何用處。事實上,當編譯成字節代碼時,優化操作會去除空 try 塊,并且不會將其包含在完成的程序中。空 try 塊可能表示被刪除或注釋掉的代碼。
例 1:下列代碼包含空 try 塊。
try {
//rs = stmt.executeQuery(query);
}
catch (SQLException e) {
log(e);
}
[1] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3050 CAT II
[2] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3050 CAT II
[3] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 561
[4] Sun Microsystems, Inc. Java Sun Tutorial