Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Error and Exception

 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand the difference between error and exception. Somebody says the error is thrown by JVM and the exception is thrown by programmers but what about the RuntimeException (subclasses thrown by JVM) and AssertionError (thrown by programmers for debugging purpose)???


 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Search First. I am sure, you will find many valuable replies.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions: Exceptions are any error or any invalid conditions that occur during the execution of program whenever any exception occure an exception object is created and thrown that contains the informatin about the information like the name of that exception or the complete stack trace which provides the information about all the methods that have been called till the time exception occur.
Exceptions can be of two type
Unchecked exceptions : All the exceptions that come under RuntimeExceptions are unchecked exceptions. These exceptions are used to denote any error that exist in the program logic. Any method that can throw the unchecked exceptions does not need to provide a explicit exception handling mechanism for those exceptions. .(do not need to be handled explicitly)

Checked Exceptions: All the exceptions that are subclasses of Exception except Runtime exception are checked exceptions. These exceptions are generally used to represent any invalid condition that occur during the execution of program. Any method that may throw the checked exception should provide a explicit exception handling mechanism to deal with those exceptions otherwise there will be a compile time error.(need to be handled explicitly)

Error: Error defines the exceptions that are not expected to be caught by the program. Like stack Overflow. Recovery from them is difficult or impossible.
 
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sudhakar Sharma wrote:. . . Somebody says the error is thrown by JVM and the exception is thrown by programmers . . .

They are mistaken. But it is possible intentionally to throw an Exception or Error or Throwable with the throw keyword.
 
Campbell Ritchie
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sudhakar Sharma wrote: . . . AssertionError (thrown by programmers for debugging purpose) . . .

It is not normal to throw an AssertionError, but to use the keyword assert, which you correctly say is used for debugging, or more precisely for checking correctness of the program. I think the AssertionError is a bit of a "cheat" because catch (Exception e) . . . is a common programming construct and the Error passes that, a bit like an unchecked Exception.
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell,

But my question is not answered ie the difference between them
 
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sudhakar

Error and Exception are subclasses of class Throwable which deals basically with exceptions in java .

Exception handling is a mechanism in which java enables you to deal with conditions that might cause your program to stop.

Dealing with it will enable you to stop the program from stopping execution at runtime and continue with further execution .

You can refer to the documentation for understanding class Throwable and its subclasses Error and Exception.

 
Campbell Ritchie
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To the Java™ Tutorials!
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic