由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 跪求大牛指点Java,看不懂什么意思。
相关主题
copy constructor都什么时候be called啊how to copy an Object?
basic java questionanonymous innerclass reflection question
有熟悉Java Reflection的吗The right way to create new Exception
Ask a simple question about throw exception, bow bow bow怎样用class的string type name 动态生成object?
where to execute java program?问个面试题, 谢谢
what's inside an java object?is it legal for the constructor of a REST resource class to throw exceptions?
How to know the size of a java object ?如何关闭打开的输入输出?
what is your opinion in this case?这段是什么语法?
相关话题的讨论汇总
话题: obj话题: java话题: class话题: exception
进入Java版参与讨论
1 (共1页)
n**********2
发帖数: 214
1
What is stale object in Java? How will you handle it? For example: You have
a Class A as shown below
public class A{
A(){
// code for database connection
}
// code for other method
}
Now,you are trying to create a object A by its constructor. To initialize
constructor it throws some exception to create database connection.
A obj = new A().
obj.amethod() ;
If obj.amethod() ; will be executed successfully or not ?
How will you stop your code not to use obj?
d****i
发帖数: 4809
2
just use try-catch pair:
try {
A obj = new A();
obj.aMethod();
} catch (Exception ex) {
//handle exception here
}

have

【在 n**********2 的大作中提到】
: What is stale object in Java? How will you handle it? For example: You have
: a Class A as shown below
: public class A{
: A(){
: // code for database connection
: }
: // code for other method
: }
: Now,you are trying to create a object A by its constructor. To initialize
: constructor it throws some exception to create database connection.

n**********2
发帖数: 214
3
大牛能稍微解释下嘛?原理是什么

【在 d****i 的大作中提到】
: just use try-catch pair:
: try {
: A obj = new A();
: obj.aMethod();
: } catch (Exception ex) {
: //handle exception here
: }
:
: have

d****i
发帖数: 4809
4
就是异常处理,如果try block的代码抛出异常,那么catch block就抓到后处理异常。
详情参见文档:
http://docs.oracle.com/javase/tutorial/essential/exceptions/

【在 n**********2 的大作中提到】
: 大牛能稍微解释下嘛?原理是什么
1 (共1页)
进入Java版参与讨论
相关主题
这段是什么语法?where to execute java program?
ZT: 关于性爱的多线程问题研究(一)what's inside an java object?
a fun coding questionHow to know the size of a java object ?
[合集] 问一个很常见的过程的实现what is your opinion in this case?
copy constructor都什么时候be called啊how to copy an Object?
basic java questionanonymous innerclass reflection question
有熟悉Java Reflection的吗The right way to create new Exception
Ask a simple question about throw exception, bow bow bow怎样用class的string type name 动态生成object?
相关话题的讨论汇总
话题: obj话题: java话题: class话题: exception