Institute of Computer Science
  1. Courses
  2. 2017/18 spring
  3. Object-Oriented Programming (Narva College) (P2NC.01.083)
ET
Log in

Object-Oriented Programming (Narva College) 2017/18 spring

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links
Session 11

Introduction

In Java, any program is analysed before its execution. Program compilations allow to detect and fix most of the errors; however, some errors occur when the program is running. Some examples:

int[] myNumbers = { 1, 2, 3 };
System.out.println(myNumbers[42]); // ArrayIndexOutOfBoundsException
int n = Integer.parseInt("text"); // NumberFormatException
String myString = null;
myString.length(); // NullPointerException

Runtime errors occur if the JVM detects an operation that is impossible to carry out while a program is running (e.g. try to access an array using an index that is out of bounds - ArrayIndexOutOfBoundsException, use a double value when your program expects an integer - InputMismatchException).

An exception is an object that represents an error or a condition that prevents execution from proceeding normally. If the exception is not handled, the program will terminate abnormally. In other words, an exception is a run-time error. How to handle the exception so that the program can continue to run or else terminate gracefully?

Session 11
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment