improved error handling and logging

Former-commit-id: d0052afd68fc4e90b915473b1a0cc6b53763dc49
This commit is contained in:
Jeremy Long
2014-01-03 08:55:29 -05:00
parent 7c7722e8fc
commit cb85292f99

View File

@@ -288,10 +288,16 @@ public class Engine {
try { try {
ensureDataExists(); ensureDataExists();
} catch (NoDataException ex) { } catch (NoDataException ex) {
final String msg = String.format("%n%n%s%n%nUnable to continue dependency-check analysis.", ex.getMessage()); final String msg = String.format("%s%n%nUnable to continue dependency-check analysis.", ex.getMessage());
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, msg); Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(Engine.class.getName()).log(Level.FINE, null, ex); Logger.getLogger(Engine.class.getName()).log(Level.FINE, null, ex);
return; return;
} catch (DatabaseException ex) {
final String msg = String.format("%s%n%nUnable to continue dependency-check analysis.", ex.getMessage());
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(Engine.class.getName()).log(Level.FINE, null, ex);
return;
} }
//phase one initialize //phase one initialize
@@ -425,8 +431,10 @@ public class Engine {
* NoDataException is thrown. * NoDataException is thrown.
* *
* @throws NoDataException thrown if no data exists in the CPE Index * @throws NoDataException thrown if no data exists in the CPE Index
* @throws DatabaseException thrown if there is an exception opening the
* database
*/ */
private void ensureDataExists() throws NoDataException { private void ensureDataExists() throws NoDataException, DatabaseException {
final CpeMemoryIndex cpe = CpeMemoryIndex.getInstance(); final CpeMemoryIndex cpe = CpeMemoryIndex.getInstance();
final CveDB cve = new CveDB(); final CveDB cve = new CveDB();
@@ -434,21 +442,21 @@ public class Engine {
cve.open(); cve.open();
cpe.open(cve); cpe.open(cve);
} catch (IndexException ex) { } catch (IndexException ex) {
throw new NoDataException(ex); throw new NoDataException(ex.getMessage(), ex);
} catch (IOException ex) { } catch (IOException ex) {
throw new NoDataException(ex); throw new NoDataException(ex.getMessage(), ex);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new NoDataException(ex); throw new NoDataException(ex.getMessage(), ex);
} catch (DatabaseException ex) { } catch (DatabaseException ex) {
throw new NoDataException(ex); throw new NoDataException(ex.getMessage(), ex);
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
throw new NoDataException(ex); throw new NoDataException(ex.getMessage(), ex);
} finally { } finally {
cve.close(); cve.close();
} }
if (cpe.numDocs() <= 0) { if (cpe.numDocs() <= 0) {
cpe.close(); cpe.close();
throw new NoDataException(); throw new NoDataException("No documents exist");
} }
} }
} }