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

Supplementary exception hints

parent e89dcf3c
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,8 @@
<listitem>
<para>Open this project in your <productname>IDEA</productname> IDE
by selecting the <filename>Exam/pom.xml</filename> file.</para>
by selecting the <filename>Exam/pom.xml</filename> file. Your home
directory is <filename>/home/student</filename>.</para>
</listitem>
</orderedlist>
</section>
......@@ -172,7 +173,26 @@
<para>So the <code language="java">switch</code> statement
implementing a jump table differs from <code>if ... else if</code>
in definitely calling <code
language="java">computeItemCount()</code> only once.</para>
language="java">computeItemCount()</code> only once. In order to
be in full accordance we'd need a small modification for the
»<code language="java">if</code>« implementation:</para>
<programlisting language="java">public static int getScore() {
final int itemCount = computeItemCount();
if (1 == itemCount) {
return 20;
} else if (3 == itemCount) {
return 50;
} else {
return 0;
}
}</programlisting>
<para>This way both implementations are in complete sync. (At
least despite runtime efficiency and possible <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/OutOfMemoryError.html">OutOfMemoryError</link>s)</para>
</answer>
</qandaentry>
</qandadiv>
......@@ -247,6 +267,13 @@ try {
} 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>
<para>Caveat: There is a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html#class-description">whole
bunch of other child classes</link> of <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
The simplified version thus potentially catches additional
exceptions we might not be aware of. </para>
</answer>
</qandaentry>
</qandadiv>
......
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