Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. PLIK: MyException.java
  2.  
  3. import java.io.*;
  4. public class MyException extends Exception {
  5.    
  6.    public MyException() {
  7.    }
  8.    
  9.    public string getMessage() {
  10.       returnThis is my message - something is wrong”;
  11.    }
  12. }
  13.  
  14.  
  15.  
  16. /* koniec pliku MyException.java ktory musisz zaincludować w pliku, ktory to rzuca
  17.  
  18.  
  19. Coś co rzuca:
  20. */
  21.  
  22. Class coś throws MyException {
  23.  
  24.     public void rób_rzeczy() {
  25.         if(something_is_wrong == true) {
  26.             throw MyException();
  27.         }
  28.     }
  29.  
  30. }
  31. /*
  32. coś co ma wyświetlić
  33.  
  34. */
  35.  
  36. try {
  37.     mój_coś.rób_rzeczy();
  38.  
  39. }
  40. Catch (MyException e1) { // mój_coś.rób_rzeczy() rzucił wyjątek.
  41.     System.out.println(e1.getMessage);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement