• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in java  RSS feed

 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


what is difference between ClassNotFoundException and NoClassDefFoundError?


Thanks in advance
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaDoc API descriptions of those classes are pretty detailed when it comes to the circumstances in which these exceptions are thrown. Have you read those, and if so, which parts are unclear to you?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One is an exception and the other an error. HUGE difference.
 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NoClassDefFoundError- is thrown at runtime when classloader not find that partciular class or jar in classpath.

ClassNotFondException is thrown when classloader not find that particular class or jar at compile -time


am i correct? anything i am missing ....

 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyanaka jaiswal wrote:NoClassDefFoundError- is thrown at runtime when classloader not find that partciular class or jar in classpath.


Read this. Specifically:

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.


Hence, the error.



priyanaka jaiswal wrote:ClassNotFoundException is thrown when classloader not find that particular class or jar at compile -time


am i correct? anything i am missing ....



Yes, it is a compile time or a checked exception. Class names are resolved during compile time and if a class by that name is not found, it throws this exception.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:One is an exception and the other an error. HUGE difference.


That doesn't even remotely answer the question.

And note that both are exceptions, but only one is an Exception.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:

Yes, it is a compile time or a checked exception. Class names are resolved during compile time and if a class by that name is not found, it throws this exception.


No.

1. There's no such thing as a "compile-time" exception.

2. All exceptions that your code may have to deal with are thrown at runtime, never at compile-time. Including ClassNotFoundException.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:One is an exception and the other an error. HUGE difference.

That doesn't even remotely answer the question.


If I had answered straightaway, the OP wouldn't have remembered what it is.

Jeff Verdegan wrote:
Mansukhdeep Thind wrote:And note that both are exceptions, but only one is an Exception.


Agreed.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:

Yes, it is a compile time or a checked exception. Class names are resolved during compile time and if a class by that name is not found, it throws this exception.


No.

1. There's no such thing as a "compile-time" exception.


I refer to it as that because it helps me remember as checked exceptions are checked for by the compiler at compile time as a part of the contract to make sure they are either handled using try-catch or declared using the throws keyword. To be precise, yes, there is nothing called as a compile time exception. Its either checked or unchecked Exception.

Jeff Verdegan wrote:
Mansukhdeep Thind wrote:2. All exceptions that your code may have to deal with are thrown at runtime, never at compile-time. Including ClassNotFoundException.


Couldn't agree more. All exceptions are thrown at runtime. I shouldn't have used the word thrown. Apologies for that. What I meant was what I just wrote above. I need to get better at expressing myself though i.e to mean what I say and to say what I mean.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not at all sure but the basic difference is - ClassNotFoundException is fired when a Java Class is not found by the compiler and NoClassDefFoundError checks about the Class file. is it?? please comment and correct.

Thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:One is an exception and the other an error. HUGE difference.

That doesn't even remotely answer the question.


If I had answered straightaway, the OP wouldn't have remembered what it is.


That doesn't mean you should post something totally useless. There's a difference bewteen "not giving them a full answer" and "giving them nothing at all."
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ishan Pandya wrote:I am not at all sure but the basic difference is - ClassNotFoundException is fired when a Java Class is not found by the compiler and NoClassDefFoundError checks about the Class file. is it?? please comment and correct.

Thanks.


Not, that is not correct. Both occur at runtime (as I already stated). If you want to know the difference, read the documentation.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:One is an exception and the other an error. HUGE difference.

That doesn't even remotely answer the question.


If I had answered straightaway, the OP wouldn't have remembered what it is.


That doesn't mean you should post something totally useless. There's a difference bewteen "not giving them a full answer" and "giving them nothing at all."


Yes Jeff. Will take care. Sorry.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!