如果你想故意抛出一个IOException(),你应该像这样简单地抛出一个新的IOException():
throw new IOException();
这是故意抛出异常的正确方法。故意引发异常并不是好的做法,因为它会使异常看起来很真实。
这里是可以抛出 IOException() 的异常子类的完整列表:
ChangedCharSetException, CharacterCodingException, CharConversionException,
ClosedChannelException, EOFException, FileLockInterruptionException,
FileNotFoundException, FilerException, FileSystemException,
HttpRetryException, IIOException, InterruptedByTimeoutException,
InterruptedIOException, InvalidPropertiesFormatException,
JMXProviderException, JMXServerErrorException, MalformedURLException,
ObjectStreamException, ProtocolException, RemoteException, SaslException,
SocketException, SSLException, SyncFailedException, UnknownHostException,
UnknownServiceException, UnsupportedDataTypeException,
UnsupportedEncodingException, UserPrincipalNotFoundException,
UTFDataFormatException, ZipException
此列表来自https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html。