【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了UseTryCatchDemo.java提供大家参考,希望对大家有所帮助!
package Chapter9;
public class UseTryCatchDemo {
public static void main(String args[]) {
String str = null;
int strLength = 0;
try {
strLength = str.length();
} catch (NullPointerException e) {
System.out.println("在求字符串长度的时候产生异常");
}
System.out.println("strLength的长度:" + strLength);
}
}