Checked and Unchecked Exception in Java



Read - Exception Handling in Java



Checked Exception

These are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using the throws keyword.


Example:

using System;  
namespace CSharpProgram  
{  
    class Program  
    {  
        static void Main(string[] args)   
        {  
                int val = int.MaxValue;  
                Console.WriteLine(val + 2);  
        }  
    }  
}

output:



Example using Checked :

This program throws an exception and stops program execution.

using System;  
namespace CSharpProgram  
{  
    class Program  
    {  
        static void Main(string[] args)