Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt  RSS feed

 
Gemi P
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the differece between exception and error
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Java In General (Beginner) forum...
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error stop the execution of the program. You are not to be able to recover from Error using try-catch statement.
For example UnsatisfiedLinkError means that JVM couln't find native language definition of a method. Your program couldn't continue without these method.

The exception shows you that something goes wrong but you could recover the state of the program, the program could continue.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, any exception can be caught but some exceptions are considered unlkely to be handled successfully by a try/catch statement.

All exceptions are subclasses of Throwable. Subclasses of Error, which extends Throwable, are hardware/software errors that are usually beyond the scope of application code. Similarly, subclasses of RuntimeException, which extends Exception, which in turn extends Throwable, represent software errors (like OutOfMemoryError) that would be hard to predict in advance well enough to handle.

This leaves all subclasses of Exception that are not also subclasses of RuntimeException. These are called checked exceptions and must always be either caught by a try/catch statement or explicitly passed to the calling method by a throws clause. Checked exceptions are considered sufficiently predictable and potentially correctable that the programmer should think about handling them and show his/her decision in the code.
[ October 04, 2004: Message edited by: Mike Gershman ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!