Question: ```
catch (Exception ex)
{
    DBGlobals.Error("OHMjson.Graph.saveLastGraphName - Error: " + ex.getMessage());
    msg = "Unable to save data";
    status = false;
}

```

This piece of code would throw an status as false, if i encounter an error. 

Instead should i thrown New exception. 
Is this the right way.
How can i handle exception in a better way.

Answer: 
First, don't catch `Exception`. Catch a specific subclass.

Second, yes it may be that an underlying `IOException`, which is what this looks like, should be wrapped in an app-specific exception. You could have, for instance:

```
final class DBGlobalsException extends Exception
{
   Field somethingDBGlobalsSpecific;

   //where this is shorthand for chained constructors that look like Exception
   DBGlobalsException(String message, Throwable cause)
   {
     super(message,cause);
   }

   // elaborate your exception with whatever error state you want to propagate outwards
   void setField(Field ...) {}
}

```

And you could then 

```
catch (IOException ex) {
   DBGlobals.Error("OHMjson.Graph.saveLastGraphName - Error: " + ex.getMessage());
   msg = "Unable to save data";
   status = false;
   DBGlobalsException dbe = new DBGlobalsException(msg,ex);
   dbe.setField(status /* or whatever */);
   throw dbe;
}

```

See also: [Throwing `Exception`](https://stackoverflow.com/questions/986695/in-java-is-using-throws-exception-instead-of-throwing-mulitple-specific-exceptio), [Throwing new and old exceptions](https://stackoverflow.com/questions/2716749/throwing-a-new-exception-while-throwing-an-old-exception), [Rolling your own](https://stackoverflow.com/questions/237585/java-lang-exception-vs-rolling-your-own-exception). That's just a few, there are a bunch of great SO Q+A's on exception handling, chaining, etc. Some useful best-practices stuff outlined at [WikiBooks](http://en.wikibooks.org/wiki/Java_Programming/Throwing_and_Catching_Exceptions).

Also read [Oded's answer](https://stackoverflow.com/questions/3950629/expection-handling/3950652#3950652) and think it through... your exception should encapsulate whatever status (error codes, flags, etc...) are required for the outer code to recover from the condition -- or it should be an unrecoverable condition (see `RuntimeException`).

Finally, the canonical Effective Java reference: [Item 43: Throw Exceptions Appropriate to the Abstraction](http://books.google.com/books?id=ZZOiqZQIbRMC&lpg=PA178&ots=UZS24scK36&dq=throw%20exceptions%20%22effective%20java%22&pg=PA178#v=onepage&q&f=false).
Prefer throwing exceptions to returning error codes/status.

Returning an error code means the caller should always remember to check for it. Throwing the exception allows the calling code to make the decision of what to do (an normally the higher up the decision, the better it can be made).