mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
CE-847 Add method getTopAndBottomMessages
This commit is contained in:
@ -164,4 +164,23 @@ public class ExceptionUtils
|
|||||||
|
|
||||||
return (StringUtils.join("; ", messages));
|
return (StringUtils.join("; ", messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Get the messages from the top & bottoms (root) of an exception.
|
||||||
|
**
|
||||||
|
** If there's no root, just return the top (e.g., parameter)'s message.
|
||||||
|
** If they are both found, put ": " between them.
|
||||||
|
*******************************************************************************/
|
||||||
|
public static String getTopAndBottomMessages(Exception e)
|
||||||
|
{
|
||||||
|
String rs = e.getMessage();
|
||||||
|
Throwable rootException = getRootException(e);
|
||||||
|
if(rootException != e)
|
||||||
|
{
|
||||||
|
rs += ": " + rootException.getMessage();
|
||||||
|
}
|
||||||
|
return (rs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,19 @@ class ExceptionUtilsTest extends BaseTest
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testGetTopAndBottomMessages()
|
||||||
|
{
|
||||||
|
assertEquals("foo", ExceptionUtils.getTopAndBottomMessages(new Exception("foo")));
|
||||||
|
assertEquals("foo: bar", ExceptionUtils.getTopAndBottomMessages(new Exception("foo", new Exception("bar"))));
|
||||||
|
assertEquals("foo: baz", ExceptionUtils.getTopAndBottomMessages(new Exception("foo", new Exception("bar", new Exception("baz")))));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Test exception class - lets you set the cause, easier to create a loop.
|
** Test exception class - lets you set the cause, easier to create a loop.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
Reference in New Issue
Block a user