1 / 3

CAPITOLO 6

CAPITOLO 6. LA GESTIONE DELLE ECCEZIONI IN JAVA. ECCEZIONI E catch/throw. Consentono di realizzare goto non locali void GrowZebra(Zebra mz) { try { for (;;) {FeedZebra(mz, new Anchovy()) ;}} catch (JunkFoodException e) { mz.Starve(); }

akando
Download Presentation

CAPITOLO 6

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. CAPITOLO 6 LA GESTIONE DELLE ECCEZIONI IN JAVA

  2. ECCEZIONI E catch/throw • Consentono di realizzare goto non locali void GrowZebra(Zebra mz) { try { for (;;) {FeedZebra(mz, new Anchovy()) ;}} catch (JunkFoodException e) { mz.Starve(); } catch (ThrowUpException e) { mz.Drink(new Digestive()); } } void FeedZebra(Zebra z, Anchovy a) { Exception away = new JunkFoodException(); Exception up = new ThrowUpException(); if (a.smells()) { throw away; } else if (z.full()) { throw up; } else { z.GiveAnchovy(a); } }

  3. ECCEZIONI PREDEFINITE E DEFINIZIONE DI ECCEZIONI • Eccezioni predefinite e ricuperabili ArithmeticException IllegalArgumentException ArrayStoreException IllegalMonitorStateException ClassCastException IllegalThreadStateException NullPointerException IndexOutOfBoundException NumberFormatException NegativeArraySizeException SecurityException • Definizione di nuove eccezioni ricuperabili class JunkFoodException extends Exception { JunkFoodException() {} }

More Related