简体   繁体   English

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

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

I recieve 3 errors in the following section of code: 我在以下代码部分中收到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());

     }
}

For both new threads, I receive 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 unreported exception java.io.IOException; must be caught or declared to be thrown as a compiler error. unreported exception java.io.IOException; must be caught or declared to be thrown为编译器错误。

In catch(IOException e) , I receive exception java.io.IOException is never thrown in body of corresponding try statement . 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

I'm new to Java and have no idea how to fix these errors. 我是Java新手,不知道如何解决这些错误。 None of the other questions about these errors seem to contain answers relevant to my code. 关于这些错误的其他问题似乎都没有包含与我的代码相关的答案。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Exception thrown in a thread normally couldn't be caught in another thread. 通常不会在另一个线程中捕获在一个线程中引发的异常。

See this link for more explanation How to catch an Exception from a thread 有关更多说明,请参见此链接。 如何从线程捕获异常

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

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