SHARE
TWEET

CatNotFound

a guest Sep 17th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import lombok.Data;
  3. import lombok.NonNull;
  4. import lombok.RequiredArgsConstructor;
  5. import lombok.extern.slf4j.Slf4j;
  6.  
  7. @Slf4j
  8. public class SimpleExceptionChecker {
  9.  
  10.     public static void foundCat(Cat cat) throws CatException {
  11.         if (cat == null)
  12.             throw new CatException("Null cat detected!");
  13.         log.info("Found cat! Word {} printed on its collar.",cat.getName());
  14.     }
  15.  
  16.     private static void callToAnimalShelter(){
  17.         log.info("We calling to animal shelter about the cat.");
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.         Cat fluffy = new Cat("fluffy"); //here: Found cat! Word fluffy printed on its collar.
  22.         Cat unknownCat  = null; //in this case:
  23.                                 /*c.e.d._Mains.CatException: Null cat detected!
  24.                                 at c.e.d._Mains.SimpleExceptionChecker.foundCat(SimpleExceptionChecker.java:13)
  25.                                 at c.e.d._Mains.SimpleExceptionChecker.main(SimpleExceptionChecker.java:25)*/
  26.  
  27.                                  //We calling to animal shelter about the cat.
  28.         try {
  29.            // foundCat(fluffy);
  30.             foundCat(unknownCat);
  31.         } catch (CatException e) {
  32.             e.printStackTrace();
  33.             callToAnimalShelter();
  34.         }
  35.     }
  36. }
  37.  
  38. @Data
  39. @RequiredArgsConstructor
  40. class Cat {
  41.     @NonNull
  42.     private String name;
  43. }
  44.  
  45. class CatException extends Throwable {
  46.     public CatException(String message) {
  47.         super(message);
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top