LECTURE -58 - PROGRAMMING IN JAVA - ERROR, TYPES OF ERRORS AND EXCEPTION HANDLING - BCA- S3.
Error
¤ An error is a term used to describe any issue that arises unexpectedly and results in incorrect output.
Types of errors
¤ Logical error: Occur due to poor understanding of problem or solution procedure.
¤ Syntactic error: Arise due to poor understanding of the language itself.
Exception
¤ Exceptions are run time anomalies or unusual conditions that a program may encounter while executing.
A mistake might lead to an error causing to program to produce
unexpected results, Errors are the wrongs that can make a program go wrong.
An error may produce an incorrect output or may terminate the execution of the program abruptly or even may cause the system to crash. It is therefore important to detect and manage properly all the possible error conditions in the program so that the program will not terminate or crash during execution.
Types of Errors
Errors may broadly be classified into two categories:
Compile-time errors
Run-time errors
Compile-Time Errors
All syntax errors will be detected and displayed by the Java compiler and therefore these errors are known as compile-time errors. Whenever the compiler displays an error, it will not create the -class file. It is therefore necessary that we fix all the errors before we can successfully compile and run the program.
Most of the compile-time errors are due to typing mistakes. Typographical errors are hard to find, We may have to check the code word by word, or even character by character. The most common problems are:
* Missing semicolons
* Missing (or mismatch of) brackets in classes and methods
* Misspelling of identifiers and keywords
* Missing double quotes in strings
* Use of undeclared variables
* Incompatible types in assignments / initialization
* Bad references to objects
* Use of = in place of = = operator And so on
Other errors we may encounter are related to directory paths. An error such as javac : command not found means that we have not set the path correctly. We must ensure that the path includes the directory where the Java executables are stored.
Run-Time Errors
Sometimes, a program may compile successfully creating the .class file but may not run properly. Such programs may produce wrong results due to wrong logic or may terminate due to errors such as stack
Most common run-time errors are:
• Dividing an integer by zero
• Accessing an element that is out of the bounds of an array
• Trying to store a value into an array of an incompatible class or type
• Trying to cast an instance of a class to one of its subclasses
• Passing a parameter that is not in a valid range or value for a method
• Trying to illegally change the state of a thread
• Attempting to use a negative size for an array
• Using a null object reference as a legitimate object reference to access a method or a variable.
• Converting invalid string to a number
• Exception Handling
• ¨ Exceptions are of two types:
• ¤ Synchronous exceptions
• n The exceptions which occur during the program execution due to some fault in the input data are known as synchronous exceptions.
• n For example: errors such as out of range, overflow, underflow.
• ¤ Asynchronous exceptions.
• n The exceptions caused by events or faults unrelated (external) to the program and beyond the control of the program are called asynchronous exceptions.
• n For example: errors such as keyboard interrupts, hardware malfunctions, disk failure.
Exceptions
An exception is a condition that is caused by a run-time error in the program. When the Java interpreter encounters an error such as dividing an integer by zero, it creates an exception object and throws it (i.e.
informs us that an error has occurred).
If the exception object is not caught and handled properly, the interpreter will display an error message and will terminate the program. If we want the program to continue with the execution of the remaining code, then we should try to catch the exception object thrown by the error condition and then display an appropriate message for taking corrective actions. This task is known as exception handling.
The purpose of exception handling mechanism is to provide a means to detect and report an exceptional circumstance so that appropriate action can be taken. The mechanism suggests incorporation of a separate error handling code that performs the following tasks:
1. Find the problem (hit the exception).
2. Inform that an error has occurred (Throw the exception)
3. Receive the error information (Catch the exception)
4. Take corrective actions (Handle the exception)
The error handling code basically consists of two segments, one to detect errors and to throw exceptions and the other to catch exceptions and to take appropriate actions.
When writing programs, we must always be on the lookout for places in the program where an exception could be generated.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «LECTURE -58 - PROGRAMMING IN JAVA - ERROR, TYPES OF ERRORS AND EXCEPTION HANDLING - BCA- S3.», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.