Example example_exceptions

Part of the full Java 9 Jigsaw modules example suite.

Authors

Migrated for Java Modules support documentation of Apache MavenTM in the course of the Maven Support & Care program by Gerd Aschemann (and other team members) as forked repository. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original.

What is this example about?

Modules in this example

  • modb, modmain

  • modmain has a Main class which is started in run.sh

Module Dependency Graph, created with DepVis

Example’s Module Dependency Graph

Example shows …​

  • Handling of exception and transferring them from one module to another.

  • Both Exceptions and RuntimeExceptions are used.

  • Both cases of exported and non-exported exceptions are shown.

  • Chaining of non-exported Exceptions and RuntimeExceptions is shown.

Output

This example uses golden master testing to ensure output consistency. The expected output is compared with actual output using verify.sh.

Expected Output

Main: pkgmain.Main, id=ID_Main_16, B: from B

pkgb.MyException: MyException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowException(B.java:13)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:25)

pkgb.MyRuntimeException: MyRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowRuntimeException(B.java:17)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:34)

pkgbinternal.MyInternalException: MyInternalException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalException(B.java:23)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:45)

pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalRuntimeException(B.java:27)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:58)

java.lang.RuntimeException: chained in B.doItChainInternalExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalExceptionToRuntimeException(B.java:33)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:71)
Caused by: pkgbinternal.MyInternalException: MyInternalException's message
	... 2 more

java.lang.RuntimeException: chained in B.doItChainInternalRuntimeExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalRuntimeExceptionToRuntimeException(B.java:39)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:80)
Caused by: pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	... 2 more

Actual Output

Main: pkgmain.Main, id=ID_Main_16, B: from B

pkgb.MyException: MyException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowException(B.java:13)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:25)

pkgb.MyRuntimeException: MyRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowRuntimeException(B.java:17)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:34)

pkgbinternal.MyInternalException: MyInternalException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalException(B.java:23)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:45)

pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalRuntimeException(B.java:27)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:58)

java.lang.RuntimeException: chained in B.doItChainInternalExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalExceptionToRuntimeException(B.java:33)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:71)
Caused by: pkgbinternal.MyInternalException: MyInternalException's message
	... 2 more

java.lang.RuntimeException: chained in B.doItChainInternalRuntimeExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalRuntimeExceptionToRuntimeException(B.java:39)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:80)
Caused by: pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	... 2 more

Maven 4 Output

Main: pkgmain.Main, id=ID_Main_16, B: from B

pkgb.MyException: MyException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowException(B.java:13)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:25)

pkgb.MyRuntimeException: MyRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowRuntimeException(B.java:17)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:34)

pkgbinternal.MyInternalException: MyInternalException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalException(B.java:23)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:45)

pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	at modb@1.0-SNAPSHOT/pkgb.B.doItThrowInternalRuntimeException(B.java:27)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:58)

java.lang.RuntimeException: chained in B.doItChainInternalExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalExceptionToRuntimeException(B.java:33)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:71)
Caused by: pkgbinternal.MyInternalException: MyInternalException's message
	... 2 more

java.lang.RuntimeException: chained in B.doItChainInternalRuntimeExceptionToRuntimeException()
	at modb@1.0-SNAPSHOT/pkgb.B.doItChainInternalRuntimeExceptionToRuntimeException(B.java:39)
	at modmain@1.0-SNAPSHOT/pkgmain.Main.main(Main.java:80)
Caused by: pkgbinternal.MyInternalRuntimeException: MyInternalRuntimeException's message
	... 2 more

Maven 4 Migration

This example was migrated to Maven 4 using the standard approach documented in the central Maven 4 Migration guide. The migration required no special configuration beyond the standard Module Source Hierarchy setup.