Java/J2EE and SOA (348 Blogs) Become a Certified Professional
AWS Global Infrastructure

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (4 Blogs)
  • Java/J2EE and SOA (345 Blogs)
  • Spring Framework (8 Blogs)

Difference Between throw throws and throwable In Java

Published on Aug 05,2019 27K Views

A major problem in Java occurs when we are working on Exception Handling. A common confusion arises amongst throw, throws, and throwable in Java. To clear all your doubts the following pointers will be covered in this “throw, throws and throwable“article:

Moving on with this article on Difference between throw, throws, and throwable in java.

eeption handling - throw throws and throwableThrow: The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw either checked or unchecked exception. The throw keyword is mainly used to throw custom exceptions.


throw Instance


throw new ArithmeticException("/ by zero");

But this exception i.e, Instance must be of type Throwable or a subclass of Throwable. For example Exception is a sub-class of Throwable and user defined exceptions typically extend Exception class. Unlike C++, data types such as int, char, floats or non-throwable classes cannot be used as exceptions.


public class GFG {
public static void main(String[] args)
// Use of unchecked Exception
try {
// double x=3/0;
throw new ArithmeticException();
catch (ArithmeticException e) 

java.lang.ArithmeticException: / by zero

Moving on with this article on Difference between throw, throws and throwable in java.

Throws In Java :

Throw is also a keyword in java which is used in the method signature to indicate that this method may throw mentioned exceptions. The caller to such methods must handle the mentioned exceptions either using try-catch blocks or using throws keyword. Below is the syntax for using throws keyword.

return_type method_name(parameter_list) throws exception_list

{ //some statements
public class UseOfThrowAndThrows { 
public static void main(String[] args) 
throws IOException

Exception in thread “main”
at UseOfThrowAndThrows.main(

Moving on with this article on Difference between throw, throws and throwable in java.

Java.lang.Throwable Class

Throwable is a super class for all types of errors and exceptions in java. This class is a member of java.lang package. Only instances of this class or it’s sub classes are thrown by the java virtual machine or by the throw statement. The only argument of catch block must be of this type or it’s sub classes. If you want to create your own customized exceptions, then your class must extend this class.

Class Declaration

Following is the declaration for java.lang.Throwable class:

  • public class Throwable
  • extends Object
  • implements Serializable


class MyException extends Throwable
//Customized Exception class
class ThrowAndThrowsExample
void method() throws MyException
MyException e = new MyException(); 
throw e;

Thus we have come to an end of this article on ‘Difference between throw, throws and throwable in java’. If you wish to learn more, check out the Java Training by Edureka, a trusted online learning company. Edureka’s Java J2EE and SOA training and certification course is designed to train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.

Got a question for us? Please mention it in the comments section of this blog and we will get back to you as soon as possible.

Upcoming Batches For Java Certification Training Course
Course NameDateDetails
Java Certification Training Course

Class Starts on 8th June,2024

8th June

SAT&SUN (Weekend Batch)
View Details

Join the discussion

Browse Categories

webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Difference Between throw throws and throwable In Java