Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class NullDataException extends RuntimeException {
  4.     private String detail;
  5.  
  6.     NullDataException(String a) {
  7.         detail = a;
  8.     }
  9.  
  10.     @Override
  11.     public String toString() {
  12.         return "NullDataException[" + detail + "]";
  13.     }
  14. }
  15.  
  16. class MethodNullReturn extends Exception {
  17.  
  18.     private boolean detail;
  19.  
  20.     MethodNullReturn(boolean b) {
  21.         detail = b;
  22.     }
  23.  
  24.     @Override
  25.     public String toString() {
  26.         return "MethodNullReturn[" + detail + "]";
  27.     }
  28. }
  29.  
  30. public class Main {
  31.  
  32.     public static void main(String[] args) {
  33.         Scanner s = new Scanner(System.in);
  34.         System.out.print("Введите строку: ");
  35.         String str = s.nextLine();
  36.         String kek = "";
  37.         try {
  38.             //concat(str);
  39.             nullIsBack(str);
  40.  
  41.         } catch (NullDataException e) {
  42.             System.out.println("caught " + e);
  43.         } catch (MethodNullReturn e) {
  44.             System.out.println("caught " + e);
  45.  
  46.         }
  47.  
  48.  
  49.     }
  50.  
  51.     public static void concat(String a) throws NullDataException {
  52.  
  53.         System.out.println("inside concat");
  54.         if (a.equals("")) {
  55.             throw new NullDataException(a);
  56.         }
  57.         String addstr = "hello, ";
  58.         String newstr = addstr.concat(a);
  59.         System.out.println(newstr);
  60.  
  61.     }
  62.  
  63.     public static Boolean nullIsBack(String a) throws MethodNullReturn {
  64.         String rez = "";
  65.         if (a.contains("asd")) {
  66.             rez = a;
  67.         } else {
  68.             rez = null;
  69.         }
  70.         if (rez == null) {
  71.             throw new MethodNullReturn(false);
  72.         }
  73.  
  74.         return true;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement