IT Community - Software Programming, Web Development and Technical Support

difference between error and an exception?

This is a discussion on difference between error and an exception? within the Java Programming forums, part of the Software Development category; What is the difference between error and an exception?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-12-2007, 04:10 AM
Arun Arun is offline
D-Web Trainee
 
Join Date: Mar 2007
Posts: 43
Arun is on a distinguished road
Default difference between error and an exception?

What is the difference between error and an exception?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-12-2007, 04:41 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: What is the difference between error and an exception?

Hi,

An error occurs when some irrecoverable situation at runtime.
But Exceptions are conditions that occur because of bad input.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-12-2007, 07:09 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: What is the difference between error and an exception?

In java there are two types of errors may occur, one is Compile time error and another one is Runtime error. Java compiler itselft validate most of the errors during the source compilation.

I think that we are using exceptions to catch if any error occurs during the program execution (runtime) time.
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-12-2007, 11:42 PM
lavanya lavanya is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 24
lavanya is on a distinguished road
Thumbs up Re: What is the difference between error and an exception?

Exception:
  • An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.
  • An exception of any kind of the virtual machine wat it does is it makes the developers to know that they have done a mistake and this is the chance to correct it..

For example:
FileNotFoundException will be thrown if the specified file does not exist

Error
  • An error is "The act or an instance of deviating from an accepted code of behavior."
  • An error is the fault of the VM..
  • An error is the subclass of the throwable that indicates the serious problems that the reasonable applications should not try to catch that
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-18-2007, 04:58 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: What is the difference between error and an exception?

ERROR

Runtime errors can be divided into low-level errors that involve violating constraints, such as:

* dereference of a null pointer
* out-of-bounds array access
* divide by zero
* attempt to open a non-existent file for reading
* bad cast (e.g., casting an Object that is actually a Boolean to Integer)

and higher-level, logical errors, such as violations of a function's precondition:

* call to Stack's "pop" method for an empty stack
* call to "factorial" function with a negative number
* call to List's nextElement method when hasMoreElements is false

Logical errors can lead to low-level errors if they are not detected. Often, it is better to detect them (to provide better feedback).

Errors can arise due to:

* User error (for example, providing a bad file name or a poorly formatted input file).

* Programmer error (i.e., a buggy program).

Exceptions

* When an error is detected, an exception is thrown. That is, the code that caused the error stops executing immediately, and control is transferred to the catch clause for that exception of the first enclosing try block that has such a clause. The try block might be in the current function (the one that caused the error), or it might be in some function that called the current function (i.e., if the current function is not prepared to handle the exception, it is "passed up" the call chain). If no currently active function is prepared to catch the exception, an error message is printed and the program stops.

Exceptions can be built-in (actually, defined in one of Java's standard libraries) or user-defined. Here are some examples of built-in exceptions with links to their documentation:

* ArithmeticException (e.g., divide by zero)
* ClassCastException (e.g., attempt to cast a String Object to Integer)
* IndexOutOfBoundsException
* NullPointerException
* FileNotFoundException (e.g., attempt to open a non-existent file for reading)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between exception and error vijayanand Java Programming 2 07-28-2008 11:51 PM
Error: command line error MIDL1001 : cannot open input file wincodec.idl midl Mramesh C# Programming 0 02-18-2008 11:07 PM
Difference between adhoc testing and error guessing? Shanthi Software Testing 1 11-16-2007 04:36 AM
How can we Handle Exception in VB.Net? anbuchezhians VB.NET Programming 2 09-10-2007 05:19 AM
Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events? Archer ASP and ASP.NET Programming 1 07-25-2007 03:19 AM


All times are GMT -7. The time now is 11:07 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0