Similar to Multiple exception catch block java 8 eclipse SO question, I have the same issue. The referenced question does not really provide a solution, though.
In a JAX-RS web service, I am trying to build a stream. Inside the stream, I am running a query and will write the results to the stream.
Here is my working code:
public StreamingOutput getExportData (int year_mo, String plant, String reqType, String payType) {
StreamingOutput stream = new StreamingOutput() {
@Override
public void write (OutputStream output) throws IOException, WebApplicationException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(output));
...
try (AdbDao dao = new AdbDao();) {
ResultSet rs = dao.getExportData(year_mo, plant, reqType, payType);
...
if (rs != null) {
while (rs.next()) {
...
}
}
} catch (JSONException | SQLException e) {
e.printStackTrace();
throw e; <-- This is the issue
}
output.flush();
output.close();
}
};
return stream;
}
The throw e;
produces the message Unhandled exception type SQLException
What do I need to do to be able to throw the exception back to my web app?