Exceptions 是否对所有异常都有效?

Exceptions is valid for all exceptions?

也许这是个愚蠢的问题,Exception 接受所有吗?例如 IOException、NoSuchAlgorithmException、InvalidKeySpecException...所以当我调用此方法时:

public String exception(Exception e){
    StringWriter errors = new StringWriter();
    e.printStackTrace(new PrintWriter(errors));
    return errors.toString();
}

它将接受所有异常并return它们具有原始异常名称?

谢谢大家,很抱歉我刚开始问这个愚蠢的问题java,我想确定这一点。

所有异常和错误的超级 class 是 Throwable。所以,我不知道你将如何使用你的方法,但是对于线程中的错误和异常处理,例如,你应该使用这个:

try { ... } catch (Throwable t) { ... }

UPD。顺便说一句,没有人限制从 Throwable 创建自己的异常并抛出它而不是 Exception 后代:

throw new Throwable() { ... };

所以,你的方法不会处理这样的异常...

是的,您的代码可以处理所有 e instanceof Exception

Exception是所有异常的基础class,在[=13]中有一个直接子class的列表=]:

AclNotFoundException, ActivationException, AlreadyBoundException, ApplicationException, AWTException, BackingStoreException, BadAttributeValueExpException, BadBinaryOpValueExpException, BadLocationException, BadStringOperationException, BrokenBarrierException, CertificateException, CloneNotSupportedException, DataFormatException, DatatypeConfigurationException, DestroyFailedException, ExecutionException, ExpandVetoException, FontFormatException, GeneralSecurityException, GSSException, IllegalClassFormatException, InterruptedException, IntrospectionException, InvalidApplicationException, InvalidMidiDataException, InvalidPreferencesFormatException, InvalidTargetObjectTypeException, IOException, JAXBException, JMException, KeySelectorException, LastOwnerException, LineUnavailableException, MarshalException, MidiUnavailableException, MimeTypeParseException, MimeTypeParseException, NamingException, NoninvertibleTransformException, NotBoundException, NotOwnerException, ParseException, ParserConfigurationException, PrinterException, PrintException, PrivilegedActionException, PropertyVetoException, ReflectiveOperationException, RefreshFailedException, RemarshalException, RuntimeException, SAXException, ScriptException, ServerNotActiveException, SOAPException, SQLException, TimeoutException, TooManyListenersException, TransformerException, TransformException, UnmodifiableClassException, UnsupportedAudioFileException, UnsupportedCallbackException, UnsupportedFlavorException, UnsupportedLookAndFeelException, URIReferenceException, URISyntaxException, UserException, XAException, XMLParseException, XMLSignatureException, XMLStreamException, XPathException