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?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, An error occurs when some irrecoverable situation at runtime. But Exceptions are conditions that occur because of bad input.
__________________ -Murali.. |
| |||
| 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... |
| |||
| Exception:
For example: FileNotFoundException will be thrown if the specified file does not exist Error
|
| |||
| 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) |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |