missing return statement }^ 1 error

missing return statement }^ 1 error

Page 1 of 1

1 Replies - 1255 Views - Last Post: 28 February 2009 - 03:10 AM Rate Topic: -----

#1 sandeepdvn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-February 09

missing return statement }^ 1 error

Posted 28 February 2009 - 01:57 AM

Hi

I'm new to Java.. infact i dnt know.. we are using some Code in SAP.We trying to retrieve host name if server....using below code..

Imports java.net.*;

public String Getcode(Container container){

//write your code here
try {
String hostName = java.net.InetAddress.getLocalHost().getHostName();
if(hostName.equals("ppi")) {
return "P";
}
else {
return "T";
}
}
catch (java.net.UnknownHostException ex)
{

}

I'm getting missing return statement } ^ 1 error error

i dnt know why it si happening.. can anybody tell me what could be the reason.. what are the modification i will have to...

Is This A Good Question/Topic? 0
  • +

Replies To: missing return statement }^ 1 error

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 291
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: missing return statement }^ 1 error

Posted 28 February 2009 - 03:10 AM

what happens if you get an exception - you need to return something even if it is null indicating an error condition
catch (java.net.UnknownHostException ex)
{

}
   return null;		 // return null or "" or some other error indicator
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1