Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Zadanie1 {
  4. public static void main(String[] args) {
  5. //1
  6.  
  7. System.out.println("poczatek");
  8.  
  9. try {
  10. int[] tab = new int[10];
  11. System.out.println(tab[15]);
  12. } catch(Exception ex) {
  13. ex.printStackTrace();
  14. }
  15. System.out.println("koniec");
  16. System.out.println();
  17.  
  18. //2
  19.  
  20. System.err.println("poczatek");
  21.  
  22. try {
  23. FileInputStream fis = new FileInputStream("C:\\1.txt");
  24. fis.close();
  25. } catch(Exception e) {
  26. e.printStackTrace();
  27. }
  28.  
  29. System.err.println("koniec");
  30.  
  31. //3
  32. System.err.println();
  33.  
  34. try {
  35. podniesArrayIndexOutOfBoundsException();
  36. } catch(ArrayIndexOutOfBoundsException e) {
  37. e.printStackTrace();
  38. }
  39. System.err.println();
  40. try {
  41. podniesFileNotFoundException();
  42. } catch(FileNotFoundException z) {
  43. z.printStackTrace();
  44. }
  45. System.err.println();
  46. try {
  47. podniesException();
  48. } catch(Exception x) {
  49. x.printStackTrace();
  50. System.err.println(x);
  51. }
  52. System.err.println();
  53. }
  54.  
  55. static void podniesArrayIndexOutOfBoundsException() throws ArrayIndexOutOfBoundsException {
  56. throw new ArrayIndexOutOfBoundsException();
  57. }
  58. static void podniesFileNotFoundException() throws FileNotFoundException{
  59. throw new FileNotFoundException("taki plik nie istnieje");
  60. }
  61. static void podniesException() throws Exception{
  62. throw new Exception("taki element nie istnieje");
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement