Topic: java的困惑 (try & catch)

  Print this page

1.java的困惑 (try & catch) Copy to clipboard
Posted by: haoyue
Posted on: 2004-07-30 10:53

我在学java的文件打操作时遇到下面一段程序不知是何意思,请各位帮我解释一下好吗?
    Try{
int.byte=system.in.read();
catch(IOException e){
system.out.println(e.toString());
}
Try和catch这两个动词是什么意思呀?

2.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: GWoo
Posted on: 2004-07-30 16:05

try和catch用于处理java里面的Exception

3.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: haoyue
Posted on: 2004-07-31 09:55

 Try{
int.byte=system.in.read();
catch(IOException e){
system.out.println(e.toString());
}
请问try和catch是怎样处理java里面的Exception的呢?我实是不知道是怎么回事,请大家指教。

4.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: ww1ww1
Posted on: 2004-08-06 14:46

try (尝试去做)里面的东西出现异常后,就跑到catch(抓住)那里把这个异常进行处理,try里面的东西就在出现异常的地方停下来不干了。

5.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: haoyue
Posted on: 2004-08-06 15:21

那这句中system.out.println(e.toString());的e.toString()是把e的错误转成字符串输出吗

6.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: joelwx
Posted on: 2004-08-07 23:27

是的。
可以考虑使用e.printStackTrace();(不知道拼对没有)
这个可以找到错误源!

7.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: bsspirit
Posted on: 2004-08-08 12:49

也是自己定义一个异常,人工throw一个属于自己的!

8.Re:java的困惑 [Re: haoyue] Copy to clipboard
Posted by: bsspirit
Posted on: 2004-08-08 12:50

toString()是一个强制转成字符串的方法。

也可以通过 +"" (加一个空串,实现转换)。

9.Re:java的困惑 (try & catch) [Re: haoyue] Copy to clipboard
Posted by: why
Posted on: 2004-08-08 22:05

haoyue:
Please try to get the answers by reading an introduction book to Java.

10.Re:java的困惑 (try & catch) [Re: haoyue] Copy to clipboard
Posted by: haoyue
Posted on: 2004-08-08 22:31

谢谢


   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