- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to pass arguments while throwing checked exception in Java
Problem Description
How to pass arguments while throwing checked exception?
Solution
This example shows how to pass arguments while throwing an exception & how to use these arguments while catching an exception using getMessage() method of Exception class.
public class Main { public static void main (String args[]) { try { throw new Exception("throwing an exception"); } catch (Exception e) { System.out.println(e.getMessage()); } } }
Result
The above code sample will produce the following result.
throwing an exception
java_exceptions.htm
Advertisements
To Continue Learning Please Login
Login with Google