尝试引发自定义异常

时间:2018-09-30 10:05:33

标签: java eclipse exception extends implements

“您应该引发与类名匹配的异常。” 以前我做了Date类和Time类。它们各自抛出InvalidDateException和InvalidTimeException并按预期工作。 当前,它们是项目的一部分,其类包括Patient,Doctor等。它们是抽象Patient类的扩展。这些类中的每一个只需要抛出与其类名匹配的异常即可。 例如,患者对象被实例化或设置为具有空的firstName或不存在的dateOfBirth。它应该抛出InvalidPatientException而不是InvalidDateException或InvalidPersonException。

This is output from the Patient class. It works as intended but I need to have only InvalidPatientExceptions

This does not do anything more than my Date class already does. Patient still gives an InvalidDateException

String receivedJson = """
[
    {
        "id": 407,
        "fact": "Monsanto once tried to genetically engineer blue cotton, to produce denim without the use of dyes, reducing the pollution involved in the dyeing process.   ",
        "reference": null,
        "image": "http:\/\/quickfacts.me\/wp-content\/uploads\/2015\/06\/fact492.png",
        "fact_id": 1
    }
]
    """;

任何有关我要做什么或参考的知识都将有所帮助。我是特例新手。

0 个答案:

没有答案