is it at all possible to type anonymous objects dy...
# getting-started
m
is it at all possible to type anonymous objects dynamically? i’m trying to do something like this:
Copy code
fun reportError(errorState: ErrorState) {
    val type = object : Exception {
         type.className = errorState.className
    }
    silentlyReportException(type)
    handleDifferentErrorStates(errorState)
}
p
What is
type.className
? Do you want to create instance of a class by a class name?
m
i think that’s the basic idea. i need an object that subtypes
Exception
in order to use the logging tool i’m using. rather than create a bunch of classes subtyping exception, i’d like to create them dynamically using the name of another class
r
Afaik, you must have all types defined at compile time. Instead, consider making an override of
Exception
that takes a class type argument and then switch off of that
p
So you do not want to declare classes and want to create instance dynamically using name of another class. How do you expect this class name should be used? Is this name of declared class? class that extends
Exception
?