GirlFriendNotFoundException 异常怎么处理?

GirlFriendNotFoundException 异常怎么处理?

package com.example.time;
public class Funny {

    public static void main(String[] args) {
        Coder me = new Coder("my name");
        getGirl(me);
    }

    private static GirlFriend getGirl(Object boy) {
        return new GirlFriend(boy);
    }

    private static class Coder {
        Coder(String name) {
        }
    }

    private static class GirlFriend {
        GirlFriend(Object boy) {
            if (boy instanceof Coder) {
                throw new GirlFriendNotFoundException("Not possible for you XD");
            } else {
                System.out.println("Found");
            }
        }
    }

    private static class GirlFriendNotFoundException extends RuntimeException {
        GirlFriendNotFoundException(String msg) {
            super(msg);
        }
    }
}

原文发布于微信公众号 - 项勇(xiangy_life)

原文发表时间:2018-11-19

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券