Best Practices for Handling Exceptions
Dealing with exceptions in your code requires following a set of best practices in order to avoid deeper issues when writing your programs. This list of common practices is of relevance to your code in order to keep some degree of professional programming consistency:
During the development process, the first piece of advice is to avoid throwing or catching the main Exception
class. You need to be as specific as possible when dealing with an exception. Therefore, a case like the following is not recommended:
public class Example13 { public static void main(String args[]) { String text = null; try { System.out.println(text.length()); } catch (Exception e) { ...