TEST: throw keyword support.

This commit is contained in:
Nikolay Igotti
2016-11-21 17:36:36 +03:00
committed by KonstantinAnisimov
parent 0cd4512dd5
commit 81811e8c3a
6 changed files with 26 additions and 2 deletions
+7 -2
View File
@@ -380,9 +380,14 @@ task intrinsic(type: UnitKonanTest) {
task link(type: LinkKonanTest) {
source = "link/src/bar.kt"
lib = "link/lib"
}
}
task for0(type: RunKonanTest) {
goldValue = "2\n3\n4\n"
source = "runtime/basic/for0.kt"
}
}
task throw0(type: RunKonanTest) {
goldValue = "Done\n"
source = "runtime/basic/throw0.kt"
}
@@ -0,0 +1,8 @@
fun main(args : Array<String>) {
val cond = 1
if (cond == 2) throw RuntimeException()
if (cond == 3) throw NoSuchElementException("no such element")
if (cond == 4) throw Error("error happens")
println("Done")
}
+7
View File
@@ -4,6 +4,7 @@
#include "Assert.h"
#include "Exceptions.h"
#include "Types.h"
#ifdef __cplusplus
extern "C" {
@@ -35,6 +36,12 @@ void ThrowClassCastException() {
RuntimeAssert(false, "Throwing is unsupported");
}
void ThrowException(KRef exception) {
RuntimeAssert(exception != nullptr && IsInstance(exception, theThrowableTypeInfo),
"Throwing something non-throwable");
RuntimeAssert(false, "Throwing is unsupported");
}
#ifdef __cplusplus
} // extern "C"
+2
View File
@@ -13,6 +13,8 @@ void ThrowNullPointerException();
void ThrowArrayIndexOutOfBoundsException();
// Throws class cast exception.
void ThrowClassCastException();
// Throws arbitrary exception.
void ThrowException(KRef exception);
#ifdef __cplusplus
} // extern "C"
+1
View File
@@ -33,6 +33,7 @@ extern const TypeInfo* theFloatArrayTypeInfo;
extern const TypeInfo* theDoubleArrayTypeInfo;
extern const TypeInfo* theBooleanArrayTypeInfo;
extern const TypeInfo* theStringTypeInfo;
extern const TypeInfo* theThrowableTypeInfo;
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
@@ -6,6 +6,7 @@ package kotlin
* @param message the detail message string.
* @param cause the cause of this throwable.
*/
@ExportTypeInfo("theThrowableTypeInfo")
public open class Throwable(open val message: String?, open val cause: Throwable?) {
constructor(message: String?) : this(message, null)