Skip to content

Commit 3ebe8ac

Browse files
committed
Added method ConfigRuntimeException.convertToRuntimeEx()
1 parent 3a27a6e commit 3ebe8ac

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

fj-core/src/main/java/org/fugerit/java/core/cfg/ConfigRuntimeException.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,37 @@ public static ConfigRuntimeException convertExMethod( String method, Exception e
6969
public static ConfigRuntimeException convertEx( Exception e ) {
7070
return convertEx( ExConverUtils.DEFAULT_CAUSE_MESSAGE, e );
7171
}
72-
72+
73+
/**
74+
* Convert the exception to ConfigRuntimeException
75+
*
76+
* RuntimeException are left unchanged
77+
*
78+
* @param baseMessage the base message
79+
* @param e the exception
80+
* @return the runtime exception
81+
*/
82+
public static RuntimeException convertToRuntimeEx( String baseMessage, Exception e ) {
83+
RuntimeException res = null;
84+
if ( e instanceof RuntimeException ) {
85+
res = (RuntimeException)e;
86+
} else {
87+
res = new ConfigRuntimeException( ExConverUtils.defaultMessage(baseMessage, e), e );
88+
}
89+
return res;
90+
}
91+
92+
93+
/**
94+
* Convert the exception to ConfigRuntimeException
95+
*
96+
* RuntimeException are left unchanged
97+
*
98+
* @param e the exception
99+
* @return the runtime exception
100+
*/
101+
public static RuntimeException convertToRuntimeEx( Exception e ) {
102+
return convertToRuntimeEx( ExConverUtils.DEFAULT_CAUSE_MESSAGE, e );
103+
}
104+
73105
}

fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ public void testEx6() {
4545
public void testEx7() {
4646
Assert.assertNotNull( ConfigRuntimeException.convertExMethod( "e" , new SQLException( "f" ) ) );
4747
}
48+
49+
@Test
50+
public void testEx21() {
51+
Assert.assertNotNull( ConfigRuntimeException.convertToRuntimeEx( new ConfigRuntimeException( "y" ) ) );
52+
}
53+
54+
55+
@Test
56+
public void testEx22() {
57+
Assert.assertNotNull( ConfigRuntimeException.convertToRuntimeEx( new IOException( "z" ) ) );
58+
}
4859

4960
@Test
5061
public void testEx8() {

0 commit comments

Comments
 (0)