Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
    • Angular
    • C
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
  • Register
  • Login
  1. Home
  2. Blogpost

How to To Resolve ArithmeticException occur in java

Date- Aug 25,2023

3454

ArithmeticException in java

In Java, the ArithmeticException is a subclass of the RuntimeException class. It is thrown when an arithmetic operation fails or produces an incorrect result. One of the most common causes of an ArithmeticException is attempting to divide by zero.

Here's an example of how an ArithmeticException can occur and how to handle it using exception handling:


package Tutorial_00;

public class Blog02 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//code that may raise exception  
	      int data=50/0; 
		System.out.println("Arithmatic Exception Occur...");
		 
			  
	}

}

In this example, attempting to divide numerator by denominator leads to an arithmetic error and triggers an ArithmeticException. The program catches the exception using a try-catch block, prints an error message, and continues executing without crashing.

The output of this program will be:


public class Blog02 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//code that may raise exception  

		  try{  
					      //code that may raise exception  
	          int data=50/0;  
		 }
				 catch(ArithmeticException e)
				     {
						   System.out.println(e);
					   }  
					   //rest code of the program   
					   System.out.println("Arithmatic Exception Resolve..."); 
			  
	}

}

It's important to use appropriate error-handling mechanisms like try-catch blocks to gracefully handle exceptions and provide useful feedback to users or developers. In scenarios where division by zero is not an acceptable operation, you can include validation checks to avoid such situations.



S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Comments

Tags

Swagger UI
Swashbuckle
SwashbuckleAspNetCore
Rest API
Postman
Api Testing
ITextSharp
Export to Pdf
AspNet Core
AspNet
C#
View to Pdf in Aspnet
Scheduler
Fibonacci series in Java
Display Fibonacci Series
First C# Program
What is C?
C
C Programming
CodeLobster
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, India   info@code2night.com

Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • XML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • PDF Editor
By Language
  • Angular
  • C
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Built with for developers