Performance: Custom exception classes
MEDIUM IMPACT
Custom exception classes affect error handling flow and can impact response time and server resource usage during exceptions.
public class MyCustomException extends RuntimeException { public MyCustomException(String message) { super(message); } } // Throwing specific custom exception throw new MyCustomException("Specific error occurred");
public class MyException extends Exception { public MyException(String message) { super(message); } } // Throwing generic Exception instead of custom throw new Exception("Error occurred");
| Pattern | Exception Specificity | Catch Blocks | Response Time Impact | Verdict |
|---|---|---|---|---|
| Generic Exception | Low | Broad catch blocks | Higher due to extra processing | [X] Bad |
| Custom RuntimeException | High | Targeted catch blocks | Lower due to precise handling | [OK] Good |