Skip to content
Snippets Groups Projects
Commit 43b42cbe authored by Goik Martin's avatar Goik Martin
Browse files

Java 17 -- 21

parent 6cc1de84
No related branches found
No related tags found
No related merge requests found
......@@ -193,12 +193,12 @@ int a = ...;
...
try {
String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) {
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) {
System.err.println(e.getMessage());
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) {
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) {
System.err.println(e.getMessage());
}</programlisting>
......@@ -225,14 +225,14 @@ try {
<answer>
<para>Both <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
and <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
are being derived from their common parent <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
All three classes share the common <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link>
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link>
method by inheritance without redefining it.</para>
<para>Our two <code>catch</code> clauses may thus be combined into
......@@ -241,10 +241,10 @@ try {
<programlisting language="java">...
try {
String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class
System.err.println(e.getMessage());
}</programlisting>
</answer>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment