package cz.muni.fi.tomp; import java.util.*; /** * Toto je dokumentacni komentar tridy ExceptionsDemo. * * */ public class ExceptionsDemo { public static void main(String[] args) { try { System.out.println(vydel(1, 0)); } catch(Exception e) { e.printStackTrace(); } } /** * Toto je dokumentacni komentar metody vydel. * * @param i delenec * @param j delitel * * @return podil i/j * * @exception Exception jestlize delitel je nula. */ public static int vydel(int i, int j) { if(j == 0) { throw new NelzeDelitNulouException("nelze delit "+i+" nulou."); } return i / j; } public static void metoda() throws Exception { String s = "ahoj"; try { throw new Exception(); /* int[] pole = new int[3]; System.out.println(pole[3]); System.out.println(s.substring(5)); System.out.println("sem se nedostane"); */ } catch(StringIndexOutOfBoundsException e) { System.out.println("vznikla vyjimka"); } catch(Throwable e) { System.out.println("vznikl objekt Throwable"); } finally { System.out.println("jsme v bloku finally"); } System.out.println("sem se dostane"); } } class NelzeDelitNulouException extends RuntimeException { public NelzeDelitNulouException(String s) { super(s); } }