title: Java exception: throw back or send as return (function output)?
body: <p>Here's the usage: I am writing classes and functions which are designed to perform a specific function/task (for eg createBuilding, destroyBuilding etc). The design I am following is that the function does not process/handle any error scenario. Its the responsibility of the caller to take an appropriate action, in case there is an error/exception. I can do this in two ways:</p>
  
  <pre><code>public void caller {
    try {
        A.createBuilding();
    catch (Exception e) {
        process exception
    }
  }
  </code></pre>
  
  <p>First approach:</p>
  
  <pre><code>public class A {
     public String createBuilding throws Exception {
       try {
          blah blah blah
       catch (Exception e) {
          throw new Exception(e);
       }
  }
  </code></pre>
  
  <p>Second approach:</p>
  
  <pre><code>public class A {
     public String createBuilding {
       StringBuffer sb = new StringBuffer();
       try {
          blah blah blah
       catch (Exception e) {
          sb.add(e.toString());
       }
       return sb.toString();
  }
  
  The user in the second case does the following:
  public void caller throws Exception {
        String st = A.createBuilding();
        if (st.contains("Exception"))
          do something;
  }
  </code></pre>
  
  <p>Assume that the called function always returns a string.</p>
  
  <p>Any comments on which approach is better? Any pitfalls/issues I am overlooking?</p>
  
  <p>Appreciate all the help!!!</p>