1 /*=========================================================================== 2 * 3 * PUBLIC DOMAIN NOTICE 4 * National Center for Biotechnology Information 5 * 6 * This software/database is a "United States Government Work" under the 7 * terms of the United States Copyright Act. It was written as part of 8 * the author's official duties as a United States Government employee and 9 * thus cannot be copyrighted. This software/database is freely available 10 * to the public for use. The National Library of Medicine and the U.S. 11 * Government have not placed any restriction on its use or reproduction. 12 * 13 * Although all reasonable efforts have been taken to ensure the accuracy 14 * and reliability of the software and data, the NLM and the U.S. 15 * Government do not and cannot warrant the performance or results that 16 * may be obtained by using this software or data. The NLM and the U.S. 17 * Government disclaim all warranties, express or implied, including 18 * warranties of performance, merchantability or fitness for any particular 19 * purpose. 20 * 21 * Please cite the author in any work or product based on this material. 22 * 23 * ============================================================================== 24 * 25 */ 26 27 package gov.nih.nlm.ncbi.ngs.error; 28 29 import gov.nih.nlm.ncbi.ngs.error.cause.LibraryLoadCause; 30 31 public class LibraryLoadError extends ExceptionInInitializerError { 32 String libName; 33 LibraryLoadCause cause; 34 String errorMessage; 35 String recommendation; 36 LibraryLoadError(String libName, String msg, LibraryLoadCause cause)37 public LibraryLoadError(String libName, String msg, LibraryLoadCause cause) { 38 this(libName, msg, cause, cause.getRecommendation()); 39 } 40 LibraryLoadError(String libName, String msg, LibraryLoadCause cause, String recommendation)41 public LibraryLoadError(String libName, String msg, LibraryLoadCause cause, String recommendation) { 42 super(generateMsg(libName, msg, cause, recommendation)); 43 44 this.libName = libName; 45 this.cause = cause; 46 this.errorMessage = generateMsg(libName, msg, cause, null); 47 this.recommendation = recommendation; 48 } 49 50 @Override getCause()51 public LibraryLoadCause getCause() { 52 return cause; 53 } 54 55 /** 56 * @return error message, without recommendation 57 */ getErrorMessage()58 public String getErrorMessage() { 59 return errorMessage; 60 } 61 62 /** 63 * @return recommendation for the user regarding error, can be null 64 */ getRecommendation()65 public String getRecommendation() { 66 return recommendation; 67 } 68 generateMsg(String libName, String msg, LibraryLoadCause cause, String recommendation)69 private static String generateMsg(String libName, String msg, LibraryLoadCause cause, String recommendation) { 70 String result = "Failed to load '" + libName + "' - " + msg; 71 if (cause != null) { 72 result += ", " + cause.getMessage(); 73 if (recommendation != null) { 74 result += "\n" + recommendation; 75 } 76 } 77 78 return result; 79 } 80 } 81