
- 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 Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to handle checked exception in Java
Problem Description
How to handle checked exception?
Solution
This example shows how to handle checked exception using catch block.
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