TEST: throw keyword support.
This commit is contained in:
committed by
KonstantinAnisimov
parent
0cd4512dd5
commit
81811e8c3a
@@ -380,9 +380,14 @@ task intrinsic(type: UnitKonanTest) {
|
|||||||
task link(type: LinkKonanTest) {
|
task link(type: LinkKonanTest) {
|
||||||
source = "link/src/bar.kt"
|
source = "link/src/bar.kt"
|
||||||
lib = "link/lib"
|
lib = "link/lib"
|
||||||
}
|
}
|
||||||
|
|
||||||
task for0(type: RunKonanTest) {
|
task for0(type: RunKonanTest) {
|
||||||
goldValue = "2\n3\n4\n"
|
goldValue = "2\n3\n4\n"
|
||||||
source = "runtime/basic/for0.kt"
|
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")
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Assert.h"
|
#include "Assert.h"
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.h"
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -35,6 +36,12 @@ void ThrowClassCastException() {
|
|||||||
RuntimeAssert(false, "Throwing is unsupported");
|
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
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ void ThrowNullPointerException();
|
|||||||
void ThrowArrayIndexOutOfBoundsException();
|
void ThrowArrayIndexOutOfBoundsException();
|
||||||
// Throws class cast exception.
|
// Throws class cast exception.
|
||||||
void ThrowClassCastException();
|
void ThrowClassCastException();
|
||||||
|
// Throws arbitrary exception.
|
||||||
|
void ThrowException(KRef exception);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ extern const TypeInfo* theFloatArrayTypeInfo;
|
|||||||
extern const TypeInfo* theDoubleArrayTypeInfo;
|
extern const TypeInfo* theDoubleArrayTypeInfo;
|
||||||
extern const TypeInfo* theBooleanArrayTypeInfo;
|
extern const TypeInfo* theBooleanArrayTypeInfo;
|
||||||
extern const TypeInfo* theStringTypeInfo;
|
extern const TypeInfo* theStringTypeInfo;
|
||||||
|
extern const TypeInfo* theThrowableTypeInfo;
|
||||||
|
|
||||||
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
|
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info);
|
||||||
void CheckCast(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 message the detail message string.
|
||||||
* @param cause the cause of this throwable.
|
* @param cause the cause of this throwable.
|
||||||
*/
|
*/
|
||||||
|
@ExportTypeInfo("theThrowableTypeInfo")
|
||||||
public open class Throwable(open val message: String?, open val cause: Throwable?) {
|
public open class Throwable(open val message: String?, open val cause: Throwable?) {
|
||||||
constructor(message: String?) : this(message, null)
|
constructor(message: String?) : this(message, null)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user