How to To Resolve ArithmeticException occur in java | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

How to To Resolve ArithmeticException occur in java

Date- Aug 25,2023

1652

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.



Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
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 | 1190
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

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts