exceptions
Download
Skip this Video
Download Presentation
Exceptions

Loading in 2 Seconds...

play fullscreen
1 / 6

Exceptions - PowerPoint PPT Presentation


  • 54 Views
  • Uploaded on

Exceptions. What are they? Why are they useful? What else can happen at runtime…?. Wouldn’t it be wonderful? Or would it? From website http://www.dribbleglass.com/subpages/strange/exceptions.htm. What are they?.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Exceptions' - frayne


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
exceptions
Exceptions
  • What are they?
  • Why are they useful?
  • What else can happen at runtime…?

Wouldn’t it be wonderful?

Or would it?

From website http://www.dribbleglass.com/subpages/strange/exceptions.htm

what are they
What are they?
  • The program seems to be running along just fine, minding its own business and all, when suddenly…

Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero

at EyeBall.look(EyeBall.java:47)

at Eye.look(Eye.java:78)

at Eye.mouseMoved(Eye.java:56)

at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:271)

at java.awt.Component.processMouseMotionEvent(Component.java:5533)

at java.awt.Component.processEvent(Component.java:5257)

at java.awt.Container.processEvent(Container.java:1966)

at java.awt.Window.processEvent(Window.java:1153)

at java.awt.Component.dispatchEventImpl(Component.java:3955)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Window.dispatchEventImpl(Window.java:1766)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Good grief!

What’s all this mean?

what are they run time errors
What are they? – Run-time errors!
  • Java detects a problem in executing the code.
  • Java “throws an exception.”
  • If you don’t “catch” the exception, the program stops and…
  • Displays “where it was” at many levels – the “dump” you see like when JavaEyes divided by zero.

 Start at the top, looking at the dump’s info!

why are they useful
Why are they useful?
  • Exceptions tell us about serious problems running the program, which Java can’t deal with.
  • We then have a chance to fix those…

Would we be better off if Java hadn’t told us?

Generic exception code:

try {

} catch (…)

what else can happen
What else can happen…?
  • Exceptions are not the only run-time error…
  • There are plenty of “runtime” errors you have to spot yourself.
    • For example…

I wanted three eyeballs, not two!

That button was supposed to say “Exit”, not “Quit”!

Why isn’t the red square moving?

and of course
And of course…
  • Hey – DoublePedant is producing the wrong output!

Rule 1 of software development is:Everything the program is supposed to do must be tested or…

It doesn’t work!!!

ad