``` class PhotoLibException : RuntimeException { ...
# announcements
b
Copy code
class PhotoLibException : RuntimeException {
    constructor(message: String, ex: Exception?): super(message, ex) {}
    constructor(message: String): super(message) {}
    constructor(ex: Exception): super(ex) {}
}
what is the appropriate way to add another property to PhotoLibException?
d
Copy code
class PhotoLibException(val newProp: PropType) : RuntimeException {
    constructor(message: String, ex: Exception?): super(message, ex) {}
    constructor(message: String): super(message) {}
    constructor(ex: Exception): super(ex) {}
}
b
Copy code
open class ErrorCodeException(val code: String?) : RuntimeException{
results in an error on
RuntimeException
saying: “this type has a constructor, and thus must be initialized here”
so i tried
Copy code
open class ErrorCodeException(val code: String?) : RuntimeException(){
then my secondary constructors fail with:
Copy code
constructor(cause: Throwable, code: String? = null) : super(cause)
“Primary constructor expected”
d
Ohhh.
I tend to pick just one constructor but I'm not what the "correct" way is.
b
yeah, i’m extending an exception which itself has multiple constructors, so i’m stuck there
d
Copy code
class PhotoLibException(val newProp: PropType, message: String, ex: Exception?) : RuntimeException(message, ex) {
}
To be honest, I don't think you need
ex
but I can't make assumptions.
b
those fields are optional, i still want to be able to create instance of my type with any of [message, cause, message&code, cause&code, message&cause, message&cause&code]
d
Copy code
class PhotoLibException() : RuntimeException {
    val newProp: PropType

    constructor(message: String, ex: Exception?, newProp: PropType): super(message, ex) { this.newProp = newProp }
    constructor(message: String, newProp: PropType): super(message) { this.newProp = newProp }
    constructor(ex: Exception, newProp: PropType): super(ex) { this.newProp = newProp }
}
b
Copy code
class MyException : RuntimeException {
    val code: String?

    constructor(cause: Throwable, code: String? = null) : super(cause) {
        this.code = code
    }

    constructor(message: String, code: String? = null) : super(message) {
        this.code = code
    }

    constructor(message: String, cause: Throwable, code: String? = null) : super(message, cause) {
        this.code = code
    }
}