Error Handling

can there be something like try{}silence(e: Exception)

just assume the error if no action is required to be taken on the error

    throw Exception("For exceptions that you do not want to work handle")
} silence(Exception)

This is a bad practice. You shouldn’t catch and ignore exceptions. Either handle them or just let the caller deal with them. This will lead to hard to find bugs in the long run, especially if you catch and ignore a base type like Exception or Throwable.
If you really want to you can still use

	throw Exception()
} catch (e: Exception){ }

But I don’t think there should be a language construct supporting this.

Extending the try/catch/finally syntax, you can’t do, but the desire to run some code with an arbitrary special context (such as suppressing exceptions) just requires a function. With inline functions, there’s no extra overhead:

inline fun silence(body: () -> Unit) {
    try {
    } catch (e: Exception) {}

fun main() {
    silence {
        println("before exception")
        throw Exception("this is silenced")
        println("warning: unreachable code")

I also reckon that you’ll regret using this construct as you’ve described it, vs. defaultHandlingForThisSpecificException { ... }

I was thinking not exactly a total snooze of the error but more of a subtle handling like the generated a log i.e

    /// thrown exception
} silence(Exception)

could generate something like

      /// thrown exeption

rather than total death

oh I used it as is because there is no actual variable assignment


      // error being handled
} silence(Exception)

compared to

    /// variable e will never be used 
} silence(e:Exception)