Skip to content

Commit

Permalink
Merge pull request #114 from NASA-PDS/reg-mgr-111
Browse files Browse the repository at this point in the history
NASA-PDS/registry-mgr#111: Update exception to message handling
  • Loading branch information
tloubrieu-jpl authored Dec 11, 2024
2 parents 6214b96 + 7f15f92 commit d6ba2a4
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/main/java/gov/nasa/pds/registry/common/util/ExceptionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
*
* @author karpenko
*/
public class ExceptionUtils
{
/**
* Extract original exception message from a stack trace.
* @param ex Exception object
* @return Original error message
*/
public static String getMessage(Exception ex)
{
if(ex == null) return "";

Throwable tw = ex;
while(tw.getCause() != null)
{
tw = tw.getCause();
}

return tw.getMessage();
public class ExceptionUtils {
/**
* Extract original exception message from a stack trace.
*
* @param ex Exception object
* @return Original error message
*/
public static String getMessage(Exception ex) {
Throwable tw = ex;
while (tw.getCause() != null) {
tw = tw.getCause();
}

// if the user is going to see "null" do a stack trace to see
// where/why it became null and fix it there by adding/keeping
// a good message.
if (tw.getMessage() == null)
ex.printStackTrace();
return tw.getMessage();
}
}

0 comments on commit d6ba2a4

Please sign in to comment.