繁体   English   中英

尽管陷入陷阱,但方法调用仍存在“未报告的异常”

[英]“Unreported exception” from method call despite catching esception

我在以下代码部分中收到3个错误:

public static void main(String[] args){

     CS_Socket cs = new CS_Socket();

     try{
         new Thread(() -> cs.EchoServer()).start();
         new Thread(() -> cs.EchoClient()).start();
       }

     catch(IOException e){

       System.out.println(e.getMessage());

     }
}

对于这两个新线程,我都收到unreported exception java.io.IOException; must be caught or declared to be thrown unreported exception java.io.IOException; must be caught or declared to be thrown为编译器错误。

catch(IOException e) ,我exception java.io.IOException is never thrown in body of corresponding try statement收到exception java.io.IOException is never thrown in body of corresponding try statement

我是Java新手,不知道如何解决这些错误。 关于这些错误的其他问题似乎都没有包含与我的代码相关的答案。

任何帮助是极大的赞赏。

通常不会在另一个线程中捕获在一个线程中引发的异常。

有关更多说明,请参见此链接。 如何从线程捕获异常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM