// Generated from "trycatch/TryCatch.java"
@file:Suppress(
 "ALWAYS_NULL",
 "PARAMETER_NAME_CHANGED_ON_OVERRIDE",
 "SENSELESS_COMPARISON",
 "UNCHECKED_CAST",
 "UNNECESSARY_LATEINIT",
 "UNNECESSARY_NOT_NULL_ASSERTION",
 "UNREACHABLE_CODE",
 "UNUSED_ANONYMOUS_PARAMETER",
 "UNUSED_PARAMETER",
 "UNUSED_VARIABLE",
 "USELESS_CAST",
 "VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL",
 "VARIABLE_WITH_REDUNDANT_INITIALIZER",
 "REDUNDANT_ELSE_IN_WHEN")

package trycatch

import javaemul.lang.*
import java.lang.AutoCloseable
import java.lang.ClassCastException
import javaemul.internal.Exceptions
import kotlin.Exception
import kotlin.NullPointerException
import kotlin.RuntimeException
import kotlin.String
import kotlin.Suppress
import kotlin.Throwable
import kotlin.assert
import kotlin.jvm.Throws

open class TryCatch {
 open fun testMultiCatch() {
  try {
   throw ClassCastException()
  } catch (e: NullPointerException) {
   throw e
  } catch (e: kotlin.ClassCastException) {
   throw e
  } catch (r: RuntimeException) {
   var r_1: RuntimeException? = r
   r_1 = null
  }
 }

 @Throws(Throwable::class)
 open fun testEmptyThrowableCatch() {
  try {
   throw ClassCastException()
  } catch (e: Throwable) {}
  try {
   throw ClassCastException()
  } catch (e_1: Exception) {} catch (e_2: Throwable) {}
 }

 @Throws(Throwable::class)
 open fun testEmptyThrowableRethrow() {
  try {
   throw ClassCastException()
  } catch (e: Throwable) {
   throw e
  }
 }

 open fun testFinally() {
  try {
   assert(true)
  } finally {}
 }

 open fun testTryWithResource() {
  try {
   var ___primaryExc: Throwable? = null
   var thing: ClosableThing? = null
   var thing2: ClosableThing? = null
   try {
    thing = ClosableThing()
    thing2 = ClosableThing()
    throw java.lang.Exception()
   } catch (___exceptionFromTry: Throwable) {
    ___primaryExc = ___exceptionFromTry
    throw ___exceptionFromTry
   } finally {
    ___primaryExc = Exceptions.safeClose(thing2, ___primaryExc)
    ___primaryExc = Exceptions.safeClose(thing, ___primaryExc)
    if (___primaryExc != null) throw ___primaryExc!!
   }
  } catch (e: Exception) {}
 }

 open fun testTryWithResourceJava9() {
  val thing: ClosableThing = ClosableThing()
  val thing2: ClosableThing = ClosableThing()
  try {
   var ___primaryExc: Throwable? = null
   var ___resource: ClosableThing? = null
   var ___resource_1: ClosableThing? = null
   try {
    ___resource = thing
    ___resource_1 = thing2
    throw java.lang.Exception()
   } catch (___exceptionFromTry: Throwable) {
    ___primaryExc = ___exceptionFromTry
    throw ___exceptionFromTry
   } finally {
    ___primaryExc = Exceptions.safeClose(___resource_1, ___primaryExc)
    ___primaryExc = Exceptions.safeClose(___resource, ___primaryExc)
    if (___primaryExc != null) throw ___primaryExc!!
   }
  } catch (e: Exception) {}
 }

 open fun testTryWithResouceOnStaticField() {
  try {
   var ___primaryExc: Throwable? = null
   var ___resource: ClosableThing? = null
   try {
    ___resource = TryCatch.closableThing
    throw java.lang.Exception()
   } catch (___exceptionFromTry: Throwable) {
    ___primaryExc = ___exceptionFromTry
    throw ___exceptionFromTry
   } finally {
    ___primaryExc = Exceptions.safeClose(___resource, ___primaryExc)
    if (___primaryExc != null) throw ___primaryExc!!
   }
  } catch (e: Exception) {}
 }

 open fun testNestedTryCatch() {
  try {
   throw java.lang.Exception()
  } catch (ae: Exception) {
   try {
    throw java.lang.Exception()
   } catch (ie: Exception) {}
  }
 }

 @Throws(Throwable::class)
 open fun testThrowGenerics() {
  throw this.getT<Exception?>(
   java.lang.Exception(),
  )!!
 }

 private fun <T> getT(t: T): T {
  return t
 }

 @Throws(Throwable::class)
 open fun testThrowBoundGenerics() {
  throw this.getThrowable<Throwable?>()!!
 }

 private fun <T: Throwable?> getThrowable(): T {
  return null as T
 }

 @Throws(Throwable::class)
 open fun <T: Throwable?> testThrowsParameterized(throwable: T) {
  throw throwable!!
 }

 open fun testMultiCatchParameterizedException() {
  try {
   throw Exception1()
  } catch (e: TryCatch.Exception2) {
   e.f("")
  } catch (e: TryCatch.Exception1) {
   e.f("")
  }
 }

 companion object {
  private val closableThing: ClosableThing? = ClosableThing()
 }

 open class ClosableThing internal constructor(): AutoCloseable {
  override fun close() {}
 }

 interface GenericInterface<T> {
  fun f(t: T) {}
 }

 open inner class Exception1 internal constructor(): java.lang.RuntimeException(), GenericInterface<String?>

 open inner class Exception2 internal constructor(): java.lang.RuntimeException(), GenericInterface<String?>
}
