interface ExceptionDemo { String compute(String s) throws NullPointerException; } class DemoOfLambdaException { public static void main(String[] args) { ExceptionDemo ed = (str) -> { if(str.length()==0 || str==null) throw new NullPointerException("No String is available"); else return "The string "+str+" has "+str.length()+" characters."; }; java.util.Scanner scan = new java.util.Scanner(System.in); System.out.println("Enter a String: "); String s = scan.nextLine(); System.out.println(ed.compute(s)); } }