Redian新闻
>
有没有7月底8月初CHICAGO考GMAT的?
avatar
有没有7月底8月初CHICAGO考GMAT的?# Business - 商学院
c*1
1
问下面哪种情况需要throw Exceptions,为什么?
1。set the capacity of a Vector to a negative value
2。一个object设置初始状态的configuration file有语法错误
3。一个在string array中搜索word的method无法找到该word
avatar
s*8
2
RT
站内联系~
avatar
g*g
3

1 and 2

【在 c*******1 的大作中提到】
: 问下面哪种情况需要throw Exceptions,为什么?
: 1。set the capacity of a Vector to a negative value
: 2。一个object设置初始状态的configuration file有语法错误
: 3。一个在string array中搜索word的method无法找到该word

avatar
q*9
4
Exceptions should only be thrown under exceptional conditions, in all the
cases, you can return some error message to indicate error. I don't
understand why we must( or better ) throw exception?
goodbug, would you explain ?
Thanks,
avatar
c*t
5
goodbug's answer is merely for general cases, not for specific senarios.
It is quite annoying to handle a lot of checked exceptions sometimes.
Unchecked exception is dangerous if not handled. Returning error code
is pretty much like checked exception, only worse since one has to check
the error. If you are going to deal with each specific error any ways,
returning error code is better.
So take-n-pick the best thing for you.

【在 q*********9 的大作中提到】
: Exceptions should only be thrown under exceptional conditions, in all the
: cases, you can return some error message to indicate error. I don't
: understand why we must( or better ) throw exception?
: goodbug, would you explain ?
: Thanks,

avatar
g*g
6
You throw exception whenever it's exceptional conditions.
Negative size is exceptional, improper configuration is exceptional
too. Exception gives caller a chance to handle the error. The processing
can be as simple as log and ignore, but should be throwed as long as the
callee cannot handle it.

【在 q*********9 的大作中提到】
: Exceptions should only be thrown under exceptional conditions, in all the
: cases, you can return some error message to indicate error. I don't
: understand why we must( or better ) throw exception?
: goodbug, would you explain ?
: Thanks,

avatar
q*9
7
Need some clarification for case 2: normally an initial configuration is
called within constructor, so we should throw and catch the exception inside
the constructor instead of throwing out of it. Is this what you mean for
case 2?
avatar
g*g
8
Depends on how serious you think the error is.
You may want to throw out of constructor to halt
the application in some case.

inside

【在 q*********9 的大作中提到】
: Need some clarification for case 2: normally an initial configuration is
: called within constructor, so we should throw and catch the exception inside
: the constructor instead of throwing out of it. Is this what you mean for
: case 2?

avatar
E*V
9
agree with you

【在 g*****g 的大作中提到】
: You throw exception whenever it's exceptional conditions.
: Negative size is exceptional, improper configuration is exceptional
: too. Exception gives caller a chance to handle the error. The processing
: can be as simple as log and ignore, but should be throwed as long as the
: callee cannot handle it.

avatar
q*9
10
Thanks, now I am going back to case 1.
Why it's better to throw exception inside set function? (Suppose that's the
reason why the question is asked).
I would gladly accept it if we assume this set function actually allocates
memory.
avatar
g*g
11
You can't allocate negative memory, what else you want to do?

the
allocates

【在 q*********9 的大作中提到】
: Thanks, now I am going back to case 1.
: Why it's better to throw exception inside set function? (Suppose that's the
: reason why the question is asked).
: I would gladly accept it if we assume this set function actually allocates
: memory.

avatar
q*9
12
can we keep the current capacity when input is negative, but throw exception
when client uses elements exceeding capacity?
Won't this save us one exception since we'll always throw when out-of-bound?
avatar
E*V
13
你是球星的马甲?

exception
bound?

【在 q*********9 的大作中提到】
: can we keep the current capacity when input is negative, but throw exception
: when client uses elements exceeding capacity?
: Won't this save us one exception since we'll always throw when out-of-bound?

avatar
g*g
14
exception is cheap, why do you want to hide an error?

exception
bound?

【在 q*********9 的大作中提到】
: can we keep the current capacity when input is negative, but throw exception
: when client uses elements exceeding capacity?
: Won't this save us one exception since we'll always throw when out-of-bound?

avatar
q*9
15
To: EUV
No, who's 球星:)
Thanks goodbug, Although I am involving in a big system but I don't see the
handling of exceptions, sometimes it's hard to decide the pros and cons with
exception. I am wondering who's really using it?
avatar
E*V
16
球星以前是linux的常客,最近很忙不太见了

the
with

【在 q*********9 的大作中提到】
: To: EUV
: No, who's 球星:)
: Thanks goodbug, Although I am involving in a big system but I don't see the
: handling of exceptions, sometimes it's hard to decide the pros and cons with
: exception. I am wondering who's really using it?

avatar
q*9
17
I see, I will stay here for a while, trying to learn from you guys.
avatar
E*V
18
如果你用linux,欢迎去linux版

【在 q*********9 的大作中提到】
: I see, I will stay here for a while, trying to learn from you guys.
avatar
q*9
19
sure, are you ban zhu in 'linux'?
avatar
E*V
20
en

【在 q*********9 的大作中提到】
: sure, are you ban zhu in 'linux'?
avatar
T*9
21
除了3都需要

【在 c*******1 的大作中提到】
: 问下面哪种情况需要throw Exceptions,为什么?
: 1。set the capacity of a Vector to a negative value
: 2。一个object设置初始状态的configuration file有语法错误
: 3。一个在string array中搜索word的method无法找到该word

avatar
s*n
22
"fail fast"

exception
bound?

【在 q*********9 的大作中提到】
: can we keep the current capacity when input is negative, but throw exception
: when client uses elements exceeding capacity?
: Won't this save us one exception since we'll always throw when out-of-bound?

avatar
k*i
23
All your other statemens are right, but exception is expensive.

【在 g*****g 的大作中提到】
: exception is cheap, why do you want to hide an error?
:
: exception
: bound?

avatar
B*e
24
Tolerance is different. Goodbug is a fan of Java.

【在 k****i 的大作中提到】
: All your other statemens are right, but exception is expensive.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。