Best way to return status flag and message from a method in Java

后端 未结 17 1260
清酒与你
清酒与你 2020-12-25 12:55

I have a deceptively simple scenario, and I want a simple solution, but it\'s not obvious which is \"most correct\" or \"most Java\".

Let\'s say I have a small authe

17条回答
  •  长情又很酷
    2020-12-25 13:25

    You could use exceptions....

    try {
        AuthenticateMethod();
    } catch (AuthenticateError ae) {         
        // Display ae.getMessage() to user..
        System.out.println(ae.getMessage());
        //ae.printStackTrace();    
    }
    

    and then if an error occurs in your AuthenticateMethod you send a new AuthenticateError (extends Exception)

提交回复
热议问题