Exception handling needs to be enhanced

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Java 21/ Windows

      A DESCRIPTION OF THE PROBLEM :
      While implementing functional interface for example, Callable, the calling function needs to handle the exception irrespective of exception being handled within the lambda expression itself.

       Callable callable = () -> {
                  try {
                      //do something
                  } catch (Exception e) {
                      //throw new Exception(e)
                  }
                  return "This is callable";
              };
              System.out.println(callable.call()); //this throws exception asking to handle the Exception.

      For non-lambda code, using this is not mandated.
      Example:


      class MyCallable implements Callable {

          @Override
          public Object call() { // removed throws Exception and handled with try-catch
              try {

              } catch (Exception e) {
                  //throw new RuntimeException(e);
              }
              return "This is callable";
          }
      }
      MyCallable myCallable=new MyCallable();
              System.out.println(myCallable.call()); //this does not throw any exception

      Hence this needs to be handled, if the lambda expression itself handles the exception and does not want the calling function to handle.


            Assignee:
            Angelos Bimpoudis
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: