Improve decoration design-pattern model of exceptions

This commit is contained in:
2020-03-15 18:33:06 +01:00
parent 2c1bae2974
commit 61e7793f24
5 changed files with 34 additions and 8 deletions

View File

@@ -3,6 +3,5 @@ package io.smnp.error
import io.smnp.environment.Environment
class EnvironmentException(exception: SmnpException, val environment: Environment) : SmnpException(
exception.friendlyName,
"${exception.message}\n\nStack trace:\n${environment.stackTrace()}"
exception.friendlyName, exception.message, exception
)

View File

@@ -1,3 +1,12 @@
package io.smnp.error
abstract class SmnpException(val friendlyName: String, message: String? = null) : Exception(message)
abstract class SmnpException(val friendlyName: String, message: String? = null, val exception: SmnpException? = null) : Exception(message) {
val exceptionChain: List<SmnpException>
get() {
if(exception == null) {
return emptyList()
}
return listOf(this, *exception.exceptionChain.toTypedArray())
}
}