Topic: (DatagramSocket)抛出异常问题!

  Print this page

1.(DatagramSocket)抛出异常问题! Copy to clipboard
Posted by: wqq0712
Posted on: 2006-08-16 17:20


......
List lst=new List(6);
DatagramSocket ds;
public Chat()
{
try{ds=new DatagramSocket(3000);}
catch(Exception ex){ex.printStackTrace();}
}
....

2个构造方法:
public List(int rows)
throws HeadlessException

public DatagramSocket(int port)
throws SocketException

2个都是有可能出现异常的~~那为什么只对DatagramSocket构造方法进行异常处理~~而List不处理呢~~而且编译运行结果还不会出错~~当然如果没对DatagramSocket做异常处理的话~是会出现编译错误的!
请问是怎么回事呢?

2.Re:(DatagramSocket)抛出异常问题! [Re: wqq0712] Copy to clipboard
Posted by: why
Posted on: 2006-08-16 19:26

HeadlessException is a RuntimeException, an unchecked exception, i.e. exceptions that are not subject to the "Catch or Specify Requirement";
SocketException is not.

3.Re:(DatagramSocket)抛出异常问题! [Re: wqq0712] Copy to clipboard
Posted by: wqq0712
Posted on: 2006-08-17 11:47

Thank you


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923