I am coming back to java after sometime and wanted to know if I want to do a catch all exception should I use catch (Exception e) or catch (Throwable t). What are the differences and pros and cons of them
You catch exceptions that you want to deal with specifically. Never catch Exception, RuntimeException, Error or Throwable unless you have a REALLY good reason to (such as preventing rogue plugins from crashing the rest of the application).
That means that most of the time, you only have to catch checked exceptions, which you should try to do using the most specific type. If there are multiple disjoint exceptions that you want to handle the same way, use a disjoint catch clause:
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Free, earth friendly heat - from the CodeRanch trailboss