3

What is the difference between ClassNotFoundException and ClassDefNotFoundException I know that both are subclass of Exception.

Got some explanation for ClassNotFoundException from this question. What is the difference between NoClassDefFoundError and ClassNotFoundException?

I read Java doc for ClassDefNotFoundException and it says:

ClassDefNotFoundException is thrown when the definition of a class cannot be found be the OWB typing system.

Please elaborate above statement, I am unaware of OWB typing system. And what exactly is the difference between both the classed and when these Exceptions are raised.

Community
  • 1
  • 1
Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • 1
    possible duplicate of [What is the difference between NoClassDefFoundError and ClassNotFoundException?](http://stackoverflow.com/questions/1457863/what-is-the-difference-between-noclassdeffounderror-and-classnotfoundexception) – apomene May 02 '14 at 11:33
  • 3
    @apomene I already mentioned that I was searching for `ClassDefNotFoundException` not `NoClassDefFoundError` and `ClassNotFoundException` I don't think this is duplicate. – Vishrant May 02 '14 at 11:35
  • I want difference between `ClassNotFoundException` and `ClassDefNotFoundException` not between `ClassNotFoundException` and `NoClassDefFoundError` – Vishrant May 02 '14 at 11:37
  • The difference is that they are not the same. A more pertinent question would be what exactly *is* ClassDefNotFoundException. It's very poorly documented. – user207421 May 02 '14 at 12:24
  • ClassDefNotFoundException is not a standard java exception whereas ClassNotFoundException is a part of standard java. You should check Oracle Warehouse Builder documentation to understand when is CLassDefNotFoundException thrown – user2881767 May 02 '14 at 12:30

2 Answers2

1

ClassNotFoundException is a core Java exception.

ClassDefNotFoundException is an "Oracle Warehouse Builder" exception (which in all likelihood just wraps a ClassNotFoundException).

Larry
  • 348
  • 1
  • 9
  • Please elaborate how `ClassDefNotFoundException` wraps `ClassNotFoundException`? as `ClassDefNotFoundException` is a subclass of `java.lang.Exception` neither I see any use of `ClassNotFoundException` – Vishrant May 02 '14 at 12:50
  • I'm not an OWB user, so I'm speculating here. Since `ClassDefNotFoundException` is an exception specific to OWB, I'd assume that it's being created in response to a `ClassNotFoundException` being thrown. – Larry May 02 '14 at 17:28
  • appreciate your finding. – Vishrant May 03 '14 at 04:53
0

A ClassNotFoundException is thrown when the reported class is not found by the ClassLoader. This typically means that the 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.

  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.

warl0ck
  • 3,356
  • 4
  • 27
  • 57
Govinda Raj
  • 55
  • 10