Hello I'm still new to programming and I have recently learned about Exceptions and how it is better to Define a exception than use a generic one. I have researched and I understand the basic idea of Creating exceptions such as using String and Throwable. However when it come to code like this:
public void sendEnvironmentExport(Environment env) throws Exception {
if (details == null) {
details = new CurrentUserDetails();
details.setPrincipal(dao.loadUser(UserServiceImpl.SYSTEM_USERNAME));
}
for (String reportDescriptor : env.getExportReports()) {
// methodName|recipient@address.com
String[] parts = reportDescriptor.split("\\|");
if (parts.length == 2) {
Method m = this.getClass().getMethod(parts[0], String.class);
m.invoke(this, parts[1]);
} else {
logger.warn("Ignoring invalid Environment.getExportReports.report: " + reportDescriptor);
}
}
}
I have no clue where to begin with creating and exception. So basically my question is. In these cases is it better to Define and exception or use a generic one?
Sorry if I am asking an unclear question I am simply trying to understand if there is any need to define an exception for methods such as this where there is no clear area if the exception being thrown.