- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
What is a Throwable class in Java?
The java.lang.Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.
Following is the declaration for java.lang.Throwable class −
public class Throwable extends Object implements Serializable
Example
Following example explains the usage of the Throwable class. Here we use the toString() method of the Throwable class to print the exception raised.
import java.lang.*; public class ThrowableDemo { public static void main(String[] args) { try {Exception2(); } catch(Throwable e) { System.err.println(e.toString()); } } public static void Exception2()throws Throwable { throw new Throwable("This is the new Exception"); } }
Output
java.lang.Throwable: This is the new Exception
- Related Articles
- What is the importance of the Throwable class and its methods in Java?
- What is the class "class" in Java?
- What is a static class in Java?
- What is a singleton class in Java?
- What is a Locale class in Java?
- What is a Nested Class in Java?
- What is a Java class library?
- PHP Throwable interface
- What is a Pair class in Java Tuples?
- What is a Septet class in Java Tuples?
- What is a Quintet class in Java Tuples?
- What is a Triplet class in Java Tuples?
- What is AbstractSequentialList class in Java?
- What is AbstractCollection class in Java?
- What is AbstractList Class in Java?

Advertisements