Exception Handling Program in Java

  • When a number is divided by zero, for example, int x = 6 / 0; This statement is syntactically correct, but zero can never divide a number mathematically. Hence, an exception is raised.
  • Connecting to a server, but the server is off.
  • Opening a file, but the file is already deleted by someone.
  • Accessing the index that is not present in the array.
    For example, in the statement int arr[] = {7, 8, 9};, the array contains three elements arr[0], arr[1], arr[2], but if someone tries to access arr[10], then it is not possible as 10th index is not present in the array leading to the generation of an exception.
  • When JVM has run out of memory.
  • User is entering some invalid data. For example, someone types 1342 when asked to write his/ her name.

Hierarchical Structure of Exception in Java

The need of handling an Exception

Types of Exception in Java




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Hacktoberfest 2020 challenge completed!

Programming Language Trends

How building our own “Typeform to Google Sheets connector” improved our productivity

If you have infrastructure on-premise or planning to have infrastructure on-premise anytime in the…

Setting Raid 0 on your Kimsufi Dedicated Server

AR Madness — our open source ARKit game tutorial! Part Three — Collision Detection

Publishing Sport Places 2/2

27 Top University Websites Using WordPress

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amansingh Javatpoint

Amansingh Javatpoint

More from Medium

Return nothing, with Java Optionals

Let’s talk about head first Java

Numbering System Edge Cases in Java

Functional Interfaces in Java