Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Defensive programming vs exception handling

843785Jan 2 2009 — edited Jan 3 2009
Hi

im new to java programming and having problems getting my head around defensive programming vs exception handling.
i've read in my uni books about design by contract and the idea of defensive programming but im having problems with it.

so say i write the code.
String container = //some value
if (container.equals.("")) // so if i am looking for a value and find a empty String
{
   throw new // a custom exception i have made for this error.
}
else
{
   //do whatever i had planned with a non-empty String
}
is this Defensive programming or exception handling. Or am i complete of base.

thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2009
Added on Jan 2 2009
19 comments
1,361 views