Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import lombok.Data;
- import lombok.NonNull;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- @Slf4j
- public class SimpleExceptionChecker {
- public static void foundCat(Cat cat) throws CatException {
- if (cat == null)
- throw new CatException("Null cat detected!");
- log.info("Found cat! Word {} printed on its collar.",cat.getName());
- }
- private static void callToAnimalShelter(){
- log.info("We calling to animal shelter about the cat.");
- }
- public static void main(String[] args) {
- Cat fluffy = new Cat("fluffy"); //here: Found cat! Word fluffy printed on its collar.
- Cat unknownCat = null; //in this case:
- /*c.e.d._Mains.CatException: Null cat detected!
- at c.e.d._Mains.SimpleExceptionChecker.foundCat(SimpleExceptionChecker.java:13)
- at c.e.d._Mains.SimpleExceptionChecker.main(SimpleExceptionChecker.java:25)*/
- //We calling to animal shelter about the cat.
- try {
- // foundCat(fluffy);
- foundCat(unknownCat);
- } catch (CatException e) {
- e.printStackTrace();
- callToAnimalShelter();
- }
- }
- }
- @Data
- @RequiredArgsConstructor
- class Cat {
- @NonNull
- private String name;
- }
- class CatException extends Throwable {
- public CatException(String message) {
- super(message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement