Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Zadanie1 {
- public static void main(String[] args) {
- //1
- System.out.println("poczatek");
- try {
- int[] tab = new int[10];
- System.out.println(tab[15]);
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- System.out.println("koniec");
- System.out.println();
- //2
- System.err.println("poczatek");
- try {
- FileInputStream fis = new FileInputStream("C:\\1.txt");
- fis.close();
- } catch(Exception e) {
- e.printStackTrace();
- }
- System.err.println("koniec");
- //3
- System.err.println();
- try {
- podniesArrayIndexOutOfBoundsException();
- } catch(ArrayIndexOutOfBoundsException e) {
- e.printStackTrace();
- }
- System.err.println();
- try {
- podniesFileNotFoundException();
- } catch(FileNotFoundException z) {
- z.printStackTrace();
- }
- System.err.println();
- try {
- podniesException();
- } catch(Exception x) {
- x.printStackTrace();
- System.err.println(x);
- }
- System.err.println();
- }
- static void podniesArrayIndexOutOfBoundsException() throws ArrayIndexOutOfBoundsException {
- throw new ArrayIndexOutOfBoundsException();
- }
- static void podniesFileNotFoundException() throws FileNotFoundException{
- throw new FileNotFoundException("taki plik nie istnieje");
- }
- static void podniesException() throws Exception{
- throw new Exception("taki element nie istnieje");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement