- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capture divide by zero exception in Java?
When you divide a number by zero an Arithmetic Exception number is thrown.
Example
public class DividedByZero { public static void main(String args[]) { int a, b; try { a = 0; b = 54/a; System.out.println("hello"); } catch (ArithmeticException e) { System.out.println("you cannot divide a number with zero"); } } }
Output
you cannot divide a number with zero
- Related Articles
- How to capture divide by zero exception in C#?
- Handling the Divide by Zero Exception in C++
- How to capture file not found exception in Java?
- Infinity or exception in Java when divide by 0?
- How to capture an exception raised by a Python Regular expression?
- How to capture null reference exception in C#?
- How to catch a divide by zero error in C++?
- How to capture out of array index out of bounds exception in Java?
- How to capture file not found exception in C#?
- How to capture out of memory exception in C#?
- How to capture and print Python exception message?
- How to capture index out of range exception in C#?
- Infinity or Exception in C# when divide by 0?
- How to create a user defined exception (custom exception) in java?
- How to rethrow an exception in Java?

Advertisements