Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-2605

Replace `catch: Throwable` clauses with `NonFatal` or `NonControl`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.11.0.0, 1.0.0
    • None
    • None

    Description

      The Kafka codebase includes a number of instances where we do `catch t: Throwable` where we should really be doing `catch NonFatal(t)` or `catch NonControl(t)` where `NonFatal` is part of the standard library and `NonControl` is something like:

      object NonControl {
         def apply(t: Throwable): Boolean = t match {
           case _: ControlThrowable => false
           case _ => true
         }
        def unapply(t: Throwable): Option[Throwable] = if (apply(t)) Some(t) else None
      }
      

      We can also use `NonControl` to replace cases like (it's more concise and has the same behaviour):

        case e: ControlThrowable => throw e
        case e: Throwable => ...
      

      Attachments

        Activity

          People

            jinxing6042@126.com Jin Xing
            ijuma Ismael Juma
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: