java中的多个try / catch执行之间是否有任何优先级?
发布时间:2020-12-15 04:57:33 所属栏目:Java 来源:网络整理
导读:在下面的程序中,有时我得到以下输出: Number Format Execption For input string: "abc"123 有时候: 123Number Format Execption For input string: "abc" try / catch块或System.out和System.err之间的优先级是否有任何优先级? 随机输出的原因是什么?
在下面的程序中,有时我得到以下输出:
Number Format Execption For input string: "abc" 123 有时候: 123 Number Format Execption For input string: "abc" try / catch块或System.out和System.err之间的优先级是否有任何优先级? 随机输出的原因是什么? 码: String str1 = "abc"; String str2 = "123"; try{ int firstInteger = Integer.parseInt(str1); System.out.println(firstInteger); } catch(NumberFormatException e){ System.err.println("Number Format Execption " + e.getMessage()); } try{ int SecondInteger = Integer.parseInt(str2); System.out.println(SecondInteger); } catch(NumberFormatException e){ System.err.println("Number Format Execption " + e.getMessage()); } 解决方法
它与try / catch以及与写入System.out和System.err的所有内容无关;它们是两个不同的流,当它们写入控制台时,您无法控制它们的交错顺序.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |