Respond to an unknown method call: Difference between revisions

Content added Content deleted
mNo edit summary
(Added Kotlin)
Line 528: Line 528:
example.ding("dong"); // alerts "tried to handle unknown method ding"
example.ding("dong"); // alerts "tried to handle unknown method ding"
// alerts "it had arguments: dong</lang>
// alerts "it had arguments: dong</lang>

=={{header|Kotlin}}==
<lang scala>// Kotlin JS version 1.1.4-3

class C // class with no methods

fun main(args: Array<String>) {
val c: dynamic = C() // 'dynamic' turns off compile time checks
try {
c.foo() // the compiler now allows this call even though foo() is undefined
}
catch (t: Throwable) {
if (t.message == "undefined is not a function") {
println("Class C does not have a method called foo")
}
else {
println(t.message)
}
}
}</lang>

{{out}}
<pre>
Class C does not have a method called foo
</pre>


=={{header|Lasso}}==
=={{header|Lasso}}==