How to throw a checked exception from a java thread?

后端 未结 9 2180
长发绾君心
长发绾君心 2020-11-28 04:45

Hey, I\'m writing a network application, in which I read packets of some custom binary format. And I\'m starting a background thread to wait for incoming data. The problem i

9条回答
  •  余生分开走
    2020-11-28 05:18

    If you really cannot do anything useful when the exception is raised you can wrap the checked exception in a RuntimeException.

    try {
        // stuff
    } catch (CheckedException yourCheckedException) {
        throw new RuntimeException("Something to explain what is happening", yourCheckedException);
    }
    

提交回复
热议问题