1 / 6

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?.

frayne
Télécharger la présentation

Exceptions

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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?

  3. 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!

  4. 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 (…)

  5. 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?

  6. 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!!!

More Related