The others have long explained why your code did not work. If you want to print output (or do other processing) after you have set the return value from your method, a general solution is to set the return value to a local variable and only return it at the end of the method. For example:
public String getStringFromBuffer() {
String returnValue;
try {
// Do some work
StringBuffer theText = new StringBuffer();
// Do more work
returnValue = theText.toString();
System.out.println(theText); // No more any error here
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
returnValue = null;
}
return returnValue;
}