search

Home  >  Q&A  >  body text

java中有返回值的函数中throw new exception会给函数返回值吗?返回值是什么?

java中有返回值的函数中throw new exception会给函数返回值吗?返回值是什么?

天蓬老师天蓬老师2802 days ago714

reply all(5)I'll reply

  • 阿神

    阿神2017-04-18 10:52:00

    Exceptions will be thrown up one level at a time, with no return value.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:52:00

    One method’s exit is return, and the other is to throw an exception. When an exception is thrown, there is no return value

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:52:00

    throw new RuntimeException(msg);
    Use try catch to catch exceptions
    e.getMessage();

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:52:00

    Throw an exception. The code that calls this method will either catch the exception or continue to throw the exception to the upper caller. There is no chance for you to receive the return value

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:52:00

    It depends on the situation. Runtime exceptions will not cause the program to interrupt, and will continue to execute, then there will be a return value. Non-runtime exceptions will directly interrupt the program, so there is no return value. If you respond to exceptions It doesn’t exist if it’s not captured

    reply
    0
  • Cancelreply