例外処理 (COBOL、Java)

COBOL Java
*> Throw an exception
declare exc = new Exception("Something is really wrong.");
 raise exc  
*> Catch an exception
declare x y as binary-long
try
  declare o as string = null 
  display o[0]  *> display first character
  
catch ex as type Exception    
  display ex
finally
  display "Finally" 
end-try
public class ExceptionHandling
{

    public static void main(String[] args) throws Exception
    {
        Exception e = new Exception("Something is really wrong."); 
        throw e; 
    }
    
    public void nullReference()
    {
        try  
        {
            String o = null;
            System.out.println(o.charAt(0));
        }
        catch (Exception f)
        {
            System.out.println(f); 
        }
        finally
        {
            System.out.println("Finally");
        }
        
    }

}

これらの例の一部は、ハーディング大学コンピューター サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。