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) { Â Â Â Â Â Â Â Â ...