Tuesday 28 August 2012

EXCEPTION HANDLING IN JAVA !!


Hello friends !! Today i am  going to tell about EXCEPTION HANDLING in Java ...

EXCEPTION HANDLING



The first question that we strike to our mind is what is EXCEPTION ??

  Exception: is a problem that arises during the execution of a program.
These are following reason by which there is a possibility to come an exception:
·         A user has entered invalid data.
·         A file that needs to be opened cannot be found.
·         A network connection has been lost in the middle of communications, or the JVM has run out of memory.
Exception Categories :
·         Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.
·         Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compliation.
·         Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

Catching Exceptions:

A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following:
try
{
   //Protected code
}
catch(ExceptionName e1)
{
   //Catch block
}
A catch statement involves declaring the type of exception you are trying to catch. If an exception occurs in protected code, the catch block (or blocks) that follows the try is checked. If the type of exception that occurred is listed in a catch block, the exception is passed to the catch block much as an argument is passed into a method parameter.

Let us take an example….through which we can easily understand how an exception may come and how we handle that exception……..
class abc
{
public static void main(String[] arg)
{
int x=10;
int y=5;
int z=5;
try{
int p=x/(y-z);
}
catch(AirthmeticException e)
{
System.out.println(“Exception”);
}
}
}
output:
Exception

There is an another example of ArrayIndexOutOfBoundException
class abc
{
Public static void main(String[] arg)
{
Int a[]={5,10};
Int b=5;
Try{
Int x=a[2]/a[1];  //exception come due to a[2] as this was not defined
}
Catch(ArrayIndexOutOfBoundException e)
{
System.out.println(“exception”);
}
}
}
Multiple catch statement:
A try block can be followed by multiple catch blocks. The syntax for multiple catch blocks looks like the following:
try
{
   //Protected code
}
catch(ExceptionType1 e1)
{
   //Catch block
}
catch(ExceptionType2 e2)
{
   //Catch block
}
catch(ExceptionType3 e3)
{
   //Catch block
}

Example of multiple catch  statement:
class abc
{
public static void main(String[] arg)
{
int x=10;
int y=5;
int z=5;
try{
int p=x/(y-z);
}
catch(ArithmeticException e)
{
System.out.println(“Exception”);
}
catch(ArrayIndexOutOfBoundException e)
{
System.out.println(“Array range”);
}
Catch(ArrayStoreException e)
{
System.out.println(“Array wrong data type”);
}
}
}
output:
Exception

Now !! You can  download the copy of this article in pdf format by just click on below download button..
If still You have any query regarding  to this  article then please post your comment i will 100% reply back  you…..Thanks……:)

38 comments:

Hello, its good piece of writing about media print, we all
understand media is a great source of information.

Visite mon site : code xbox live gold gratuit 48h 2013 ()

Excellent goods from you, man. I've understand your stuff previous to and you're juat too fantastic.
I actually like what you've acquired here, really like what you're saying and the way in which you say it.
Youu make iit entertaining and you still take care of to keep itt sensible.
I can't wait to read much more from you. This
is really a wonderful web site.

Heree is my web blog: At&t Iphone 5c

Hi,its nice piece of writing about media print, we all be aware of media is a impressive source
of facts.

my blog At&t iphone 5s unlocked, kiwibox.com,

Good post. I learn something totally neww and challenging on sites I stumbleupon everyday.

It's always interesting to read through articles from other writers
and practice somethinhg from other websites.

Stop by my blog: boost mobile 520 cocoa florida

May I simply say what a relief to uncover somebody that actually understands what
they are discussing on the internet. You certtainly realize how to bring a problem to light
and make it important. More and more people should look at this aand understand this side of the story.
It's surprising you aren't more populasr because you
definitely have the gift.

Review mmy site - photon q boost mobile

I have to thank you for the efforts youu hasve put in writing this site.
I really hope to view the same high-grade blog posts from you in the future as well.
In fact, your creative writing abilities has inspired
me to get my owwn blog now ;)

Review my web blog :: boost mobile 3g apn settings - -

WOW just what I was searching for. Came here byy searching for at&t block a number

Visit my homepage ... galaxy 2 at&t ()

I do agree with all of the concepts you have presented for your
post. They're very convincing and can definitely work. Nonetheless, the
posts are too short for newbies. Could you please
prolong them a little from next time? Thank you for the post.


Feel free to surf to my webpage - xbox360

Howdy! I know this is knd of off topic but I was wondering which blog platform are you using ffor this site?

I'm getting fed up of Wordpress because I've had issues wuth hackkers and I'm looking at alternatives for another platform.
I would be awesome if you could point me iin the
direction of a good platform.

Here is mmy webpage: at&t 4g phones -
-

Link exchange is nothing else except it is simply placing the other person's website link on your page
at proper place and other person will also do same for you.


my web page ... at&t xtras ()

Hurrah! At last I got a web site from where I
be able to really get helpful data regarding my
study and knowledge.

Stop by my web-site x360

Right away I am going away to do my breakfast, nce having my breakfast comijg yet again to read other news.



Feel free to surf to my blog; at&t commercial old
peoople ()

fantastic put up, very informative. I ponder why the other experts of this sector do
not notice this. You must continue your writing.
I'm confident, you have a great readers' base already!

Also visit my site: boost mobile upcoming phones 2014

Hey! This is kind of off topic but I need some guidance ffrom an established blog.

Is itt very hard to set up your own blog? I'm not very techinhal
but I cann figure things out pretty fast. I'm thinking about creating my own but I'm not sure where to start.
Do you have any ideas orr suggestions? With thanks

Feel free to visit my page :: verizon 02740

I read this paragraph fully regarding the comparison of latest and previous technologies, it's awesome article.


Visit my weblog - mortal kombat games

You've made some decent points there. I looked on the internet to learn more about thhe issue and found most people
will go along with your views on thnis wweb site.

my website: boost mobile trade in

Oh my goodness! Amazing article dude! Many thanks, However I am experiencing difficulties with your RSS.
I don't understand why I cannot join it.
Is there anybody els getting identical RSS issues? Anyhone who knows the solutioon wil yoou kindly respond?
Thanks!!

Stop by my web page ... Verizon Network Not Responding

Awesome blog! Is your theme custom made or did you download it from
somewhere? A design like yours with a few simple adjustements
would really mmake my blog stand out. Please let me know where you got your theme.
Bless you

Here iis my blog: at&t moto g unboxing - ,

What i do not understood is in reality how you're no lonver actuallly
much more well-preferred than you may be now. You are very intelligent.

You already kknow tnus considerably in relation to this matter,
made me individually consider it from numerous numerous angles.
Its like women and men aare not interesed until it is one thing to accomplish with Girl
gaga! Your personal stuffs great.All the time maintain it
up!

my web site - verizon pay your bill, ,

Good day very nice site!! Man .. Excellent .. Supeerb
.. I'll bookmark your web site and take the feeds also?

I am glad to search out so maany helpful information right
here within the put up, we'd like work out more techniques in this regard, thanks for sharing.
. . . . .

my web site :: at&t outage ()

I want to to thank you for this very good read!!
I certainly loved every bit of it. I have you book marked to check out new stuff you post…

Here is my webpage ... boost mobile freee service (support-remote.splashtop.com)

Wow! At last I goot a webpage from where I know how to in fact take valuable facts regarding
myy study and knowledge.

My web site: Paul O'neill At&T

I really like your blog.. very nice colors & theme. Did you create this
website yourself or did you hire someone to doo it for you?
Plz answer basck as I'm looking to create my own blog and would like to find out where u got this from.
kudos

Here is my web site at&t customer care 24 hours ()

Thank you for sharing your info. I truly appreciate your efforts and I aam waiting for your next write
upps thanks once again.

Stop by my webpage ... at&t network problems

Hi there, just became alert to your blog through Google,
and fond that it is truly informative. I'm going to watcch outt for brussels.
I will appreciate if you continue this in future. Numerous people will
be benefited from your writing. Cheers!

My website: at&t add money ()

Just wish tto say your article is as astonishing. The clearness in your publish is just spectacular and i could assume you are an expert oon this subject.
Welll together with your permission alow
me to grasp your RSS feed to stay updated with coming near near post.
Thank you one million and please carry oon the enjoyable work.


my web page boost mobile galaxy prevail 2

Hello to every body, it's my first vsit of this weblog; this weblog consists of awesome and truly fine material in favor of visitors.


my web blog :: verizon 8 mile

I'm not sur where you're getting your info, but good
topic. I needs to spend some time learning more or understanding more.

Thanks for wonderful information I was looking for this information for my mission.

My weblog: moto g boost mobile

Thanks for sharing your thoughts. I truly appreciate
your efforts and I am waiting for your furrher write ups
thanks once again.

Feeel free to surf too my website :: boost mobile chirp sound effect

I am sure this article has touched all the internet users, its really really nice post on building up new website.


Here is my blog post: boost mobile byod ()

It's very effortless to find out any topic on net as compared to books, as I found
this piece of writing at this website.

My homepage ... at&T Ice t

Its such as you leearn my mind! You appear to grasp so much approximately this, like
you wrote the book inn it oor something. I think that you cohld do with some p.c.
to force thee message house a little bit, however instead
of that, this is excellent blog. A great read.
I'll certainly be back.

My webpage ... boost mobile galaxy 3

Right away I am going to do my breakfast, when having my brekfast coming over again to read firther news.



Visit my site verizon 3G speed slow

Hey I am so delighted I found your blog, I really found you by error,
while I wwas researching on Bing forr something else, Regardless I am
here now and would just lijke to say many thanks for
a incredible post and a all round exciting blog (I also lov the theme/design),
I don’t have time to go through it all at the moment but I have book-marked
it and also added your RSS feeds, so when I have time Iwill bbe back to read more, Please do keep up the excellent jo.


Here is my website: at&t moto x

Have you ever though about publishing an ebook
or guest authoring on other sites? I have a blog based upon on the same information you discuss aand
would lov to have you share some stories/information. I know
my viewers would appreciate your work. If you're even remotely
interested, feel free to send me an e-mail.

My webpage :: lg volt boost mobile unboxing ()

Hi there to every one, the contents existing at this web page are really amaing for
people experience, well, keep up the good work fellows.


Here is my weblog :: boosst mobile 8 mile hayes - -

When someone writes an post he/she keeps the
thought of a ser in his/her mind that how a user can understand
it. So that's why this paragraph is outstdanding. Thanks!


Here is my blog verizon 4g nott working -
-

Whenn I initially left a comment I appear to have clicked on the -Notify me
when new comments are added- checkbox and from now on each time a comment is added I get 4 emails with the
exact same comment. Is there an easy method you are able
to remove mee from that service? Kudos!

My webpage - verizon 60640

Post a Comment

Hey thanax alot to comment i will revert you back soon...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites