diff --git a/Doc/Sd1/errorHandling.xml b/Doc/Sd1/errorHandling.xml index 35f5026e2765325c1e006e83345609a777cd494f..c74c66f6bdb844d815d39149fde147a3609a880d 100644 --- a/Doc/Sd1/errorHandling.xml +++ b/Doc/Sd1/errorHandling.xml @@ -67,7 +67,8 @@ System.out.println(s.length());</programlisting> <programlisting language="java">... if (somethingBadHappens) { - throw new NullPointerException(); + throw new <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/NullPointerException.html#%3Cinit%3E()">NullPointerException()</link>; } ...</programlisting> @@ -83,7 +84,8 @@ if (somethingBadHappens) { <programlisting language="java">final String s = null; try { System.out.println(s.length()) ; -} catch (final NullPointerException e) { +} catch (final <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/NullPointerException.html">NullPointerException</link> e) { System.out.println("Dear user, something bad just happened"); } System.out.println("Business as usual ...");</programlisting> @@ -147,7 +149,8 @@ System.out.println("Business as usual ...");</programlisting> relationship we are being left with the runtimes default terminating behaviour:</para> - <screen>Exception in thread "main" java.lang.NullPointerException + <screen>Exception in thread "main" <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/NullPointerException.html">java.lang.NullPointerException</link> at exceptionhandling.NpeMsg.main(NpeMsg.java:8)</screen> </answer> </qandaentry> @@ -187,7 +190,8 @@ System.out.println("Business as usual ...");</programlisting> destPath = Paths.get("/tmp/copy.java"); // Compile time error: - // <emphasis role="red">Unhandled exception: + // <emphasis role="red" + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/IOException.html">Unhandled exception: java.io.IOException</emphasis> Files.copy(sourcePath, destPath); ...</programlisting></td> @@ -259,15 +263,19 @@ public void copyFile() throws IOException { <answer> <para>We catch the exception in question:</para> - <programlisting language="java">@Test(expected = FileAlreadyExistsException.class) + <programlisting language="java"><link + xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Test.html">@Test</link>(<link + xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Test.html#expected()">expected</link> = <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileAlreadyExistsException.html">FileAlreadyExistsException</link>.class) public void copyFile() throws IOException { final Path source = Paths.get("/tmp/source.txt"), dest = Paths.get("/tmp/dest.txt"); try { - Files.copy(source, dest); // May work. - Files.copy(source, dest); // Failure: FileAlreadyExistsException - } catch (final FileAlreadyExistsException e) { + <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#copy(java.nio.file.Path,java.nio.file.Path,java.nio.file.CopyOption...)">Files.copy(source, dest)</link>; // May work. + <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#copy(java.nio.file.Path,java.nio.file.Path,java.nio.file.CopyOption...)">Files.copy(source, dest)</link>; // Failure: FileAlreadyExistsException + } catch (final <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileAlreadyExistsException.html">FileAlreadyExistsException</link> e) { System.out.println("Destination file already exists"); } }</programlisting> @@ -280,7 +288,8 @@ public void copyFile() throws IOException { <screen>Destination file already exists -java.lang.AssertionError: Expected exception: java.nio.file.FileAlreadyExistsException</screen> +java.lang.AssertionError: Expected exception: <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileAlreadyExistsException.html">java.nio.file.FileAlreadyExistsException</link></screen> </answer> </qandaentry> </qandadiv> @@ -291,10 +300,11 @@ java.lang.AssertionError: Expected exception: java.nio.file.FileAlreadyExistsExc <title>Variants</title> <figure xml:id="sd1_errorHandling_fig_justFinally_"> - <title>Just <code language="java">finally</code></title> + <title>Just <code language="java">finally</code>, no <code + language="java">catch</code></title> <programlisting language="java"><link - xlink:href="https://docs.oracle.com/javase/10/docs/api/java/util/Scanner.html">Scanner</link> scanner = null; + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/util/Scanner.html"> Scanner</link> scanner = null; try { scanner = new <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/InputStream.html">Scanner(</link>System.in); @@ -371,7 +381,7 @@ public class StackTrace { }</programlisting></td> <td valign="top"><screen>Exception in thread "main" - java.lang.NullPointerException + <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/NullPointerException.html">java.lang.NullPointerException</link> at ex.Trace.c(Trace.java:10) at ex.Trace.b(Trace.java:7) at ex.Trace.a(Trace.java:6) @@ -386,13 +396,17 @@ public class StackTrace { <informaltable border="0"> <tr> <td valign="top"><programlisting language="java">try { - FileInputStream f = new FileInputStream( - new File("test.txt")); -} catch(FileNotFoundException e) { + <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/FileInputStream.html">FileInputStream</link> f = new <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/FileInputStream.html#%3Cinit%3E(java.io.File)">FileInputStream( + new File("test.txt"))</link>; +} catch(final <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/FileNotFoundException.html">FileNotFoundException</link> e) { System.err.println( "File not found"); -} catch (IOException e) { +} catch (final <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/IOException.html">IOException</link> e) { System.err.println( "IO error"); -} catch(Exception e) { +} catch(final <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Exception.html">Exception</link> e) { System.err.println("General error"); }</programlisting></td> @@ -411,13 +425,16 @@ public class StackTrace { <informaltable border="0"> <tr> <td valign="top"><programlisting language="none">try { - FileInputStream f = new FileInputStream( - new File("test.txt")); + FileInputStream f = new <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/FileInputStream.html">FileInputStream</link>( + new <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/File.html#%3Cinit%3E(java.lang.String)">File("test.txt"))</link>; } catch(Exception e) { System.err.println("General error"); -} catch (<emphasis role="red">IOException e</emphasis>) { +} catch (<emphasis role="red" + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/IOException.html">IOException e</emphasis>) { System.err.println( "IO error"); -} catch(<emphasis role="red">FileNotFoundException e</emphasis>) { +} catch(<emphasis role="red" + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e</emphasis>) { System.err.println("File not found"); }</programlisting></td> @@ -500,10 +517,11 @@ static public String convert(final String input) { <title>Step 2: Derive <classname>CardinalException</classname></title> <programlisting language="java">public class CardinalException - extends IllegalArgumentException { + extends <link + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/IllegalArgumentException.html">IllegalArgumentException</link> { public CardinalException(final String msg) { - super(msg); + <link xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/IllegalArgumentException.html#%3Cinit%3E(java.lang.String)">super(msg)</link>; } }</programlisting> </figure> @@ -518,7 +536,7 @@ static public String convert(final String input) { * @throws CardinalException If input not from list. */ static public String convert(final String input) - throws CardinalException{ + throws CardinalException { switch (input) { case "one": return "first"; @@ -534,11 +552,14 @@ static public String convert(final String input) { <title>Step 4: Unit test throwing <classname>CardinalException</classname></title> - <programlisting language="java">@Test public void testRegular() { - Assert.assertEquals("second", Cardinal.convert("two")); + <programlisting language="java"><link + xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Test.html">@Test</link> public void testRegular() { + Assert.<link + xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Assert.html#assertEquals(java.lang.Object,%20java.lang.Object)">assertEquals("second", Cardinal.convert("two")</link>); } -@Test(expected = CardinalException.class) +<link xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Test.html">@Test</link>(<link + xlink:href="https://junit.org/junit4/javadoc/latest/org/junit/Test.html#expected()">expected</link> = CardinalException.class) public void testException() { Assert.assertEquals("X", Cardinal.convert("four")); }</programlisting> diff --git a/Doc/Sd1/inheritance.xml b/Doc/Sd1/inheritance.xml index caa241fd60e4df3170e147afdf20c75d0b1fdd5c..afb72dc687b95804943a461bb6acc3b357fed919 100644 --- a/Doc/Sd1/inheritance.xml +++ b/Doc/Sd1/inheritance.xml @@ -1356,7 +1356,7 @@ System.out.println(c.equals(c)); // true: Object equal to itself.</programlist <figure xml:id="sd1_inherit_fig_rectangleEquals"> <title>Implementing <classname>Rectangle</classname>.<methodname - xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object-">equals()</methodname></title> + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object)">equals()</methodname></title> <programlisting language="java">public class Rectangle extends Shape { @Override public boolean equals(Object o) { @@ -1379,7 +1379,7 @@ System.out.println(c.equals(c)); // true: Object equal to itself.</programlist <figure xml:id="sd1_inherit_fig_circleEquals"> <title>Implementing <classname>Circle</classname>.<methodname - xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object-">equals()</methodname></title> + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object)">equals()</methodname></title> <programlisting language="java">public class Circle extends Shape { @Override public boolean equals(final Object o) { diff --git a/Doc/Sd1/workingWithNumbers.xml b/Doc/Sd1/workingWithNumbers.xml index b75024d005e81ddc4eb9c17816636933ff1dc4ab..2f04d2df9dc91f7bd419f0002d89562e99bccf80 100644 --- a/Doc/Sd1/workingWithNumbers.xml +++ b/Doc/Sd1/workingWithNumbers.xml @@ -54,7 +54,7 @@ while (!values.empty()) { <itemizedlist> <listitem> <para><methodname - xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object-">public + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#equals-java.lang.Object)">public boolean equals</methodname>(<classname xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html">Object</classname> obj)</para> @@ -62,7 +62,7 @@ while (!values.empty()) { <listitem> <para><methodname - xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#hashCode--">public + xlink:href="https://docs.oracle.com/javase/10/docs/api/java/lang/Object.html#hashCode()">public int hashCode()</methodname></para> </listitem> </itemizedlist>