I have helper class in which I have written this function.
public static String createProject(Map<String, String> params,String projectName, String projectPrefix) {
String createdProject = null;
try {
createdProject=//logic for creating createdProject string which may throw two exception mentioned below
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (TestLinkAPIException t) {
t.printStackTrace();
}
return createdProject;
}
Now, I am calling this function from GUI part where I have written
String createProject=//called above function.
Now, If error occurs in above code, I want to show the error to the user.
My question is, how do I get back the created string and error message if some Exception
occurs?
Create a Custom Exception
Add your String value as an instance field of that Custom Exception.
Throw the custom exception with the String values passed in.
Now you have the exception and the String as well.