File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Error and Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error and Exception" Watch "Error and Exception" New topic
Author

Error and Exception

Sudhakar Sharma
Ranch Hand

Joined: Apr 04, 2009
Posts: 71

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)???


Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Please Search First. I am sure, you will find many valuable replies.
john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 92
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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

Joined: Apr 04, 2009
Posts: 71

Thanks Campbell,

But my question is not answered ie the difference between them
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

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.


Understanding is Everything - Peter Lord
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
To the Java™ Tutorials!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error and Exception
 
Similar Threads
K&B Exception Handling Question
Identifying Exception types
Exception types
Distinguishing b/w programmer thrown exceptions and JVM thrown exceptions.
Exception Handling