title: Kotlin constructor properties and calling different superclass constructors
body: <p>I'd like to use a kotlin data class as an exception, which seems fine:</p>
  
  <pre><code>data class MyException(val extraData: Any) : RuntimeException()
  </code></pre>
  
  <p>I'd also like to be able to pass in a <code>cause</code> to the super class in those cases where one exists. Unfortunately, data classes can only have <code>val</code>/<code>var</code> in their primary constructor, and since the default constructor calls the no-args <code>RuntimeException()</code> constructor, it seems that I simply cannot do this without always requiring <code>cause</code> to be passed, <em>and</em> stored as a field in my class, which I don't want.</p>
  
  <p>What I want is something like this:</p>
  
  <pre><code>data class MyException(val extraData: Any) : RuntimeException() {
      constructor(extraData: Any, cause: Throwable) : this(extraData) super(cause) {}
  }
  </code></pre>
  
  <p>It seems that even if I don't use a data class, I still can't use the convenient <code>var</code>/<code>val</code> constructor helpers, since they can only be on a primary constructor which must chose which super constructor to use. The best I can come up with is this, which is quite verbose:</p>
  
  <pre><code>class MyException : RuntimeException {
      val extraData: Any
  
      constructor(extraData: Any) {
          this.extraData = extraData
      }
  
      constructor(extraData: Any, cause: Throwable) : super(cause) {
          this.extraData = extraData
      }
  }
  </code></pre>
  
  <p>Am I missing something? Is there really no way of conditionally calling a different super-class constructor based on overloaded constructors and still being able to use the <code>var</code>/<code>val</code> parameter syntax? If so, why? Are there better ways of doing this sort of thing?</p>