简体   繁体   English

ClassNotFoundException和ClassDefNotFoundException之间有什么区别

[英]What is the difference between ClassNotFoundException and ClassDefNotFoundException

What is the difference between ClassNotFoundException and ClassDefNotFoundException I know that both are subclass of Exception . ClassNotFoundExceptionClassDefNotFoundException什么区别我知道它们都是Exception子类。

Got some explanation for ClassNotFoundException from this question. 从这个问题得到了ClassNotFoundException一些解释。 What is the difference between NoClassDefFoundError and ClassNotFoundException? NoClassDefFoundError和ClassNotFoundException有什么区别?

I read Java doc for ClassDefNotFoundException and it says: 我为ClassDefNotFoundException读了Java doc ,它说:

ClassDefNotFoundException is thrown when the definition of a class cannot be found be the OWB typing system. 当OWB类型系统找不到类的定义时,抛出ClassDefNotFoundException

Please elaborate above statement, I am unaware of OWB typing system. 请详细说明以上声明,我不知道OWB打字系统。 And what exactly is the difference between both the classed and when these Exceptions are raised. 分类和提出这些例外时到底有什么区别。

ClassNotFoundException is a core Java exception. ClassNotFoundException是一个核心Java异常。

ClassDefNotFoundException is an "Oracle Warehouse Builder" exception (which in all likelihood just wraps a ClassNotFoundException ). ClassDefNotFoundException是一个“Oracle Warehouse Builder”异常(很可能只是包装了一个ClassNotFoundException )。

A ClassNotFoundException is thrown when the reported class is not found by the ClassLoader. 当ClassLoader找不到报告的类时,抛出ClassNotFoundException This typically means that the class is missing from the CLASSPATH . 这通常意味着class is missing from the CLASSPATH

Suppose we have a class named as X has reference to Class Y. Classloader loads the class X, It's loaded now it goes through linking phase where it goes through three different subphases. 假设我们有一个名为X的类引用了类Y.Classloader加载了类X,它现在加载它经过linking phase ,它通过三个不同的子阶段。

  1. Verification-phase 验证阶段
  2. Prepare-phase 准备阶段
  3. Resolve-phase. 解决相。

Now when it goes through Resolve-phase and this phase try to resolve reference of Y and unfortunately it does not find the definition of class Y, then It will be ClassDefNotFoundException for Class Y and it will wrap 'ClassNotFoundException' for class X. 现在当它通过Resolve-phase并且这个阶段尝试解析Y的引用时,遗憾的是它没有找到类Y的定义,那么它将是Class Y的ClassDefNotFoundException ,它将为类X包装'ClassNotFoundException'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM