Java:为什么PrintWriter或PrintStream类不引发异常? [英] Java: Why don't the PrintWriter or PrintStream classes throw exception?

查看:108
本文介绍了Java:为什么PrintWriter或PrintStream类不引发异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PrintWriter和PrintStream绝不会抛出IOExceptions

问题有点奇怪。但是我很想知道为什么两个 PrintWriter PrintStream 不检查自动运行时异常,它们提供了checkError()方法。

Maybe the question is a bit "strange". But i'm curious to know why both PrintWriter and PrintStream don't check automatically runtime exceptions , and they provides a checkError() method.

预先感谢大家。

推荐答案

对于经常写入std out或err的PrintStream,这些流可能已被关闭或丢弃,但是您不希望程序因此意外失败。

For PrintStream which is often writing to std out or err, these stream might have been closed or discarded but you don't want the program to fail unexpectedly as a results.

PrintWriter在许多方面都是PrintStream的Writer版本,尽管我不确定重复PrintStream的错误是一个好主意。 ;)

PrintWriter is in many ways the Writer version of PrintStream, though I am not sure it was a good idea to repeat the mistakes of PrintStream. ;)

PrintWriter没有报告IOException的事实使它成为将文本写入Socket的不佳选择,在Socket中您经常需要知道连接已失败。

The fact PrintWriter doesn't report IOException makes it a poor choice for writing text to a Socket where you often need to know the connection has failed.

这篇关于Java:为什么PrintWriter或PrintStream类不引发异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆