gpt4 book ai didi

java - 打印或 println 中的 IOException

转载 作者:搜寻专家 更新时间:2023-11-01 03:14:00 25 4
gpt4 key购买 nike

大部分 IO 操作都需要 try catch block 或 throws 。为什么 System.out.print 或 println 不需要 try catch 或 throws。如果这些方法中有任何异常,我怎么知道异常是什么以及如何捕获它。

最佳答案

您可以通过调用来检查错误

System.out.checkError();

javadoc of PrintStream.checkError()说:

returns true if and only if this stream has encountered an IOException other than InterruptedIOException, or the setError method has been invoked

如果你真的想监视 System.out 的异常,你可以将你自己的 PrintStream 设置为 System.out 并覆盖你的方法有兴趣。

关于java - 打印或 println 中的 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3846881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com