Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is <code>a</code> or <code>b</code> assigned if an exception occurs? Wrap <code>a</code> and <code>b</code> in a <code>Try</code> to handle the exceptional cases. You can also pattern match on these to extract values.</p> <pre><code>scala&gt; class MyClass(val a: Try[String], val b: Try[String]) defined class MyClass scala&gt; new MyClass(Try("foo"(0).toString), Try("foo"(3).toString)) res0: MyClass = MyClass@6bcc9c57 scala&gt; res0.a res1: scala.util.Try[String] = Success(f) scala&gt; res0.b res2: scala.util.Try[String] = Failure(java.lang.StringIndexOutOfBoundsException: String index out of range: 3) scala&gt; res0.a.get res3: String = f scala&gt; res0.b.get java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt(String.java:658) ... </code></pre> <p><strong>Edits for comment. Uses default argumens for <code>a</code> and <code>b</code></strong>.</p> <p><code>null</code> is bad but that's what you asked for. See <a href="http://www.scala-lang.org/api/current/index.html#scala.Option" rel="nofollow">Option</a></p> <pre><code>class MyClass(val a: Try[String] = null, val b: Try[String] = null) scala&gt; new MyClass(Success("a")) res50: MyClass = MyClass@625aaaca scala&gt; res50.a res51: scala.util.Try[String] = Success(a) scala&gt; res50.b res52: scala.util.Try[String] = null scala&gt; new MyClass(b = Success("b")) res53: MyClass = MyClass@68157e85 scala&gt; res53.a res54: scala.util.Try[String] = null scala&gt; res53.b res55: scala.util.Try[String] = Success(b) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload