I have a method which uses java.util.Date
and java.util.Calendar
objects to give me current time with timezone and one of my colleague recommended to add try catch with Exception
e to catch. But when I searched on google about any exception thrown with the inbuild methods of these classes I don't find any.
Do I still need to wrap the code with try and catch??? Is try catch required for the block as simple as below:
try{
Date dto = Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(dto);
String dateString = calendar.getTime().toString();
return dateString;
}catch(Exception e){
e.getMessage();
}