What is the exception in java code? [closed]
- by Karandeep Singh
This java code is for reverse the string but it returning concat null with returned string.
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Practice {
public static void main(String[] args) {
String str = "";
try {
str = reverse("Singh");
} catch (Exception ex) {
Logger.getLogger(Practice.class.getName()).log(Level.SEVERE, null, ex);
System.out.print(ex.getMessage());
}finally{
System.out.println(str);
}
}
public static String reverse(String str) throws Exception{
String temp = null;
if(str.length()<=0){
throw new Exception("empty");
}else{
for(int i=str.length()-1;i>=0;i--){
temp+=str.charAt(i);
}
}
return temp.trim();
}
}
Output:
nullhgniS