*
The moose likes Beginning Java and the fly likes Understanding Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Understanding Exceptions" Watch "Understanding Exceptions" New topic
Author

Understanding Exceptions

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Okay.. so I understand the basic concepts of exceptions. I guess what I don't understand is this extending a class and the base class catches the exception. How is this set up?
And could someone clearly describe checked exceptions to me.
I guess I basically need someone to show me some complex examples of programs that use exceptions. I understand the simpler ones.
Thanks
Dale

------------------
What's this H2SO4 doing in my fridge?? ( thud )


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

From my understanding about checked exceptions:
If you declare that a method in your class will throw an
exception e.g.
public method() throws MyException {}
and MyException inherits from java.lang.Exception, then this
is a checked exception. A client that calls method() will cause
the compiler to check that it is caught or rethrown. If not, a compiler time error is flagged.
But if MyException extends RunTimeException, then nothing of the above happens.
Pho


Regards,

Pho
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10

Try this code with no command line arguments
Try it using a letter (or anything other than an integer)

A checked exception is checked at compile time. It must either be caught or declared as thrown. A runtime exception (example ArithmeticException) will not be caught by the compiler but may be thrown at runtime (example division by zero).


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Exceptions:
"On June 4, 1996, the maiden flight of the European Ariane 5 launcher crashed about 40 seconds after takeoff. Media reports indicated that the amount lost was half a billion dollars -- uninsured.
The CNES (French National Center for Space Studies) and the European Space Agency immediately appointed an international inquiry board, made of respected experts from major European countries, who produced their report in hardly more than a month.
Its conclusion: the explosion was the result of a software error -- possibly the costliest in history (at least in dollar terms, since earlier cases have caused loss of life).
The exception was due to a floating-point error: a conversion from a 64-bit integer to a 16-bit signed integer, which should only have been applied to a number less than 2^15, was erroneously applied to a greater number, representing the "horizontal bias" of the flight. There was no explicit exception handler to catch the exception, so it followed the usual fate of uncaught exceptions and crashed the entire software, hence the on-board computers, hence the mission."
http://www.eiffel.com/doc/manuals/technology/contract/ariane/page.html
Just to illustrate how important it is to catch an exception

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I am hereby a true believer !


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Understanding Exceptions
 
Similar Threads
Doubt Regarding Anonymous Inner Classes
Study kit example doubt
Unexpected death of a thread
Checked and JVM Exceptins
class Private?