I'm using a method that gets JSON data from an API, in Java whenever I use getJSONObject I have to surround the method with a try/catch, since it detects that the method throws a JSONException, I want to be able to force the programmer to surround my function in Kotlin when it's used. 
The method on which I want to do this is the following:
@Throws(JSONException::class)
    fun parseHitEvents(jsonObject: JSONObject): MutableList<AlgoliaEvent> {
        val hits = jsonObject.optJSONArray("hits")
        val results = ArrayList<AlgoliaEvent>(hits.length()) // Initialize the array list to be of size hits.length
        hits?.forEach<JSONObject> { hit ->
            // Check that each hit is not null
            if (hit == null) return@forEach
            // Parse each hit with a correspond ConciseEvent object
            val event = jsonToObject<ConciseEvent>(hit).apply {
                // We need to get the values from AbstractQuery.LatLng and add them into each event object
                with(hit.getJSONObject("_geoloc")) {
                    _geoloc.lat = getDouble("lat")
                    _geoloc.lng = getDouble("lng")
                }
            // Add the main event in the list of events, so that we can send them as the return value
            results.add(AlgoliaEvent(HitEvent(event)))
        }
        return results
    }
However, when this method is being called in another file, I'm not being forced to surround the method in a try/catch.
Is there a way to do that, or is there a way to implement this kind of logic in a better way?


