Skip to content

Commit

Permalink
Use KClass in exception constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jkly committed Sep 20, 2018
1 parent c39789f commit 53f9321
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ashley/src/main/kotlin/ktx/ashley/engines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ktx.ashley
import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.Engine
import com.badlogic.ashley.core.Entity
import kotlin.reflect.KClass

/**
* An [Entity] created by the provided [Engine].
Expand Down Expand Up @@ -48,8 +49,8 @@ inline fun <reified T : Component> Engine.create(configure: T.() -> Unit = {}):
return try {
createComponent(T::class.java)
} catch (e: Exception) {
throw CreateComponentException(T::class.java, e)
}?.apply(configure)?:throw CreateComponentException(T::class.java)
throw CreateComponentException(T::class, e)
}?.apply(configure)?:throw CreateComponentException(T::class)
}

/**
Expand All @@ -73,4 +74,4 @@ inline fun Engine.entity(configure: EngineEntity.() -> Unit = {}): Entity {
return entity
}

class CreateComponentException(type: Class<*>, cause: Throwable? = null): RuntimeException("Could not instantiate component ${type.name} - the component must have a visible no-arg constructor", cause)
class CreateComponentException(type: KClass<*>, cause: Throwable? = null): RuntimeException("Could not instantiate component ${type::java.name} - the component must have a visible no-arg constructor", cause)

0 comments on commit 53f9321

Please sign in to comment.