1.ide eccezioni - Unife

15
!"#$%&'% )$ *+$,-../ 0!+! % %11%2$/&$ !"#$ !&'() *&++,+&- !"#$%&'"(()("*+,#$'"&$- *'3-"%&'$ 0!+! .%3 ,/ *+$,-../ )$ $&'%34!11% -'%&'% % *%3+$2$ )$ 3%'% % ,/3/ !..,$1!2$/&% 56789:;< .()"+)& /&+ 0, /+"1+,22,3("'& 425(&'6& 7( )8(09//" :;!<= ?&)@"'& 7&00& &AA&3("'(

Transcript of 1.ide eccezioni - Unife

Page 1: 1.ide eccezioni - Unife

!"#$%&'%()$(*+$,-../(0!+!(%(

%11%2$/&$(

!"#$%!&'()%*&++,+&-%%

!"#$%&'"(()("*+,#$'"&$-.

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

56789:;<(

•  .()"+)&%/&+%0,%/+"1+,22,3("'&%

•  425(&'6&%7(%)8(09//"%:;!<=>%•  ?&)@"'&%7&00&%&AA&3("'(%

Page 2: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

6=>86>:(?:6(@5(?68765995A=8;:(

B4C4%7(%D4E<F%–  GHI&%B,8,%H96"+(,0J%:K,8,$)9'$A"2L7"A)L5""M)L696"+(,0=>%

%G/0".1)2)./,-3($)4%.)(".5()676)4.8,$!"%.'3(.5(38()99"(%.:03.:)#-.-3.,%".-0".1)2).5(38()99$#8.4)#8,)8".-3.6(")-".)554$6)73#%&./0";.$#64,!".0,#!("!%.3'.63954"-"<.:3(=$#8.">)954"%<.)#!.!3?"#%.3'.4"%%3#%&@..

–  B!N%!"A92&'6,@"'%:K,8,$)9'$A"2LK,8,)&LOL7"A)=>%

–  B4C4%4P;%:K,8,$)9'$A"2LK,8,)&LOL7"A)L,/(=>%%A".B554$6)73#.C(38()99$#8.D#-"(')6".!"#<.%3#3.38#$.$#%$"9".!$.5(36"!,(".!$%53#$E$4$<.$#.8"#"(".()88(,55)-".).'3(9)(".,#.%"-.!$.%-(,9"#7.%5"6$F6$.5"(.,#.!"-"(9$#)-3.6395$-3&.

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

6=>86>:(?:6(@5(?68765995A=8;:(

Q;D.;F%–  GHI('M('1%('%B,8,JR%D+9A&%<AM&0%:SSS$5+9A&&AM&0$A"2=>%

Q;TNF%

–  %SSS$2"M,5U6&$(6R%+(8()6,%(6,0(,',%)9%B,8,%

C&+)("'&%,#9,0&%7(%B4C4%:V&55+,("%WXYX=F%

%B,8,%E<%!&8&0"/2&'6%N(6%:B!N=%%O%9/7,6&%YZ%

/&+%7&#,10(%I#/FLLK,8,$)9'$A"2LK,8,)&LOLV&,69+&)$K)/%

Page 3: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

59B=:;<(C=(>D=@E??8(

•  T&65&,')%:FFFG;:HB:5;>G867=R%/"6&'6&%,25(&'6&%7(%)8(09//"%290@[0('19,11("%)A+(#"%('%B4C4$%\]A(,02&'6&%%)A&06"%7,%E\T$%:1+,69(6"=>%

•  <A0(/)&%:FFFG:I@=?>:G867=R%9'%;!<%1+,69(6"%A"'%2"06&%V9'3("'(%9@0($%

•  B\'(6%:FFFGJE;=HG867=R%/&+%(0%6&)@'1$%

•  B^+&,6"+%:FFFGJI6:5H86GI89=R%V,A(0&%&%0&11&+"$%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

59B=:;<(C=(>D=@E??8(T"(%9@0(33&+&2"%B^+&,6"+$%

?(_%(')6,00,6"%('%0,5"+,6"+("$%

OUTPUT

PACKAGE VIEW

FILE VIEW

Page 4: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(`1'(%,//0(A,3("'&%7&8&%&))&+&%,))"A(,6,%,7%9'%a"+M)/,A&L/+"1&#"$%

•  ^+&,+&%(0%'9"8"%P+"K&A6$%*(0&%[b%T&S%[b%P+"K&A6%

•  E&0&3("',+&%G<2/6U%P+"K&A6J%

•  EA&10(&+&%7"8&%),08,+&%(0%/+"1&#"$%

•  4))&1',+&%9'%'"2&%,0%/+"1&#"$%Gc&00"a"+07J$%

•  `N$%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(^+&,+&%(0%d0&%A"'6&'&'6&%(0%A"7(A&$%

•  E&0&3("',+&%*(0&%[b%T&Se%:)A&10(&+&%(0%6,5%G*(0&)J=>%

•  EA&10(&+&%GB,8,%*(0&J%

•  !,+&%9'%'"2&%,0%d0&%:A"'%&)6&')("'&%$K,8,=>%

•  `N%

Assicurarsi che sia selezionato “Add to Project”

Page 5: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(^+&,+&%(0%d0&%7&0%A"7(A&$%

•  ;'%*(0&C(&S%)&0&3("',+&%(0%S"+M)/,A&%,//&',%A+&,6"$%

•  <%('7(8(79,+&%(0%d0&%A+&,6"$%

•  EA+(8&+&%(0%A"7(A&$%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(N(

public class Hello {

public static void main(String[] args){

System.out.println("Hello World!"); }

}

Page 6: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(O(public class Hello {

public static void main(String[] args){

if (args.length >= 1) { System.out.println("Hello " + args[0] + "!"); } else { System.out.println("Hello World!"); } }

}

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(^"2/(0,+&%&7%&)&19(+&$%

•  ^0(AM%)9%G^"2/(0&%P+"K&A6J%:+(AI(&7&%(0%),08,6,11("%7&0%d0&=$%

•  ^0(AM%)9%G<f&A96&%P+"K&A6J%$%

Compile project

Execute project

Output della compilazione e dell’esecuzione

Output dell’esecuzione

Page 7: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(P,)),+&%7&10(%,+1"2&'@%,0%g,('%9),'7"%B^+&,6"+$%

Selezionare “Configuration” dal menu del bottone “Execute Project”

Selezionare la configurazione di Default e “Edit…”

Selezionare l’applicazione di Default e “Edit…”

Selezionare il tab “Parameters” e cliccare su “Prompt for…”

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(400,%)9AA&))(8,%&)&A93("'&R%8&++_%AI(&)6"%7(%(')&+(+&%10(%,+1"2&'@$%

Page 8: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

016:5H86(K(L:@@8(M86@C(<)&19(+&%(0%/+"1+,22,%7,%+(1,%7(%A"2,'7"$%

4))(A9+,+)(%AI&%(0%/&+A"+)"%7"8&%+()(&7"'"%GK,8,$&f&J%&%GK,8,A$&f&J%)(,%'&0%P4Hc%7(%)()6&2,$%

Compilazione

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(H:86=5(Q%*'$/&%()%Q,$(%33/3$(

•  E/&))"%8(%)"'"%()6+93("'(%GA+(@AI&JR%AI&%('%A&+@%A,)(%/"))"'"%/+"79++&%&++"+($%

•  Qh,//+"AA("%A0,))(A"%A"')()6&%'&00h(')&+(+&%A"'6+"00(%:(Ve%&0)&$$=%/&+%A&+A,+&%7(%('6&+A&#,+&%,%/+("+(%0&%)(69,3("'(%A+(@AI&$%

•  g,%i%9'%2"7"%7(%/+"A&7&+&%)/&))"%(')"77()V,A&'6&%/&+AIj%'"'%i%V,A(0&%%/+&8&7&+&%69#&%0&%)(69,3("'(%AI&%/"6+&55&+"%/+"79++&%0h&++"+&$%

•  Q:><6:%0h&++"+&%)/&))"%)(1'(dA,%)"0"%)6,2/,+&%,%8(7&"%9'%2&)),11("$%

Page 9: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(H:86=5(B,8,%('6+"79A&%(0%A"'A&#"%7(%:II:A=8;:G(

•  4'3(AIj%6&'6,+&%7(%/+&8&7&+&%0&%)(69,3("'(%7(%&++"+&R%)(%6&'6,%7(%&)&19(+&%0h"/&+,3("'&%('%9'%50"AA"%A"'6+"00,6"$%

•  E&%)(%/+"79A&%9'%&++"+&R%0h"/&+,3("'&%>8@@:D5(E;R:II:A=8;:G(

•  Qh&AA&3("'&%8(&'&%I5SE65H5%7,0%50"AA"%&'6+"%A9(%0h"/&+,3("'&%i%&)&19(6,e%

•  e&%/9k%&))&+&%7:><H5%'&0%2"7"%/(l%,//+"/+(,6"$%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(H:86=5(try {

//operazione critica che può sollevare eccezioni } catch (Exception1 e1) { //gestione dell’eccezione } catch (Exception2 e2) { //gestione dell’eccezione } finally { //codice da eseguire comunque dopo il blocco try

}

•  E&%0h"/&+,3("'&%)"00&8,%C=D:6>=(<?=(C=(:II:A=8;:(=;(6=>?8>H5(5(C=D:6>=(<?=(C=(:6686:R%/(l%50"AAI(%catch%/"))"'"%)&19(+&%0"%)6&))"%50"AA"%try

Page 10: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(:>:9?=8(1/&+%3*$/&%(*'3$&Q!T&-"%3/(

;'%B,8,%0,%A"'8&+)("'&%)6+('1,b'92&+"%('6&+"%i%)8"06,%7,0%2&6"7"%)6,@A"%%

int Integer.parseInt(String s)!

•  Qh"/&+,3("'&%i%I6=<I5R%/&+AIj%/9k%,88&'(+&%)"0"%)&%@5(>H6=;75(C5H5(I8;<:;:(@5(65??6:>:;H5A=8;:(C=(E;(;E9:68(=;H:68G(

•  E&%A(k%'"'%,AA,7&%(0%2&6"7"%parseInt%)"00&8,%9',%NumberFormatException

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(:>:9?=8(public class NumeroIntero {

public static void main(String[] args) { int numero = 0; String n = "ciao"; try {

numero = Integer.parseInt(n); } catch (NumberFormatException e) { System.out.println("Errore: stringa mal fatta."); System.exit(-1); } System.out.println("Il numero inserito è " + numero); }

}

Page 11: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(:>:9?=8(public class NumeroIntero {

public static void main(String[] args) { int numero = 0; String n = "ciao"; try {

numero = Integer.parseInt(n); } catch (NumberFormatException e) { System.out.println("Errore: stringa mal fatta."); System.exit(-1); } System.out.println("Il numero inserito è " + numero); }

}

Catturare le eccezioni è importante: un’eccezione non catturata si propaga verso l’esterno, di blocco in blocco: se raggiunge il main, provoca l’aborto del programma

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(K(I8>5(>8;8U(

•  \',%&AA&3("'&%i%9'%877:S8R%()6,'3,%7(%java.lang.Throwable%"%7(%9',%)9,%)"#"A0,))&$%

Q&%79&%)"#"A0,))(%/(l%A"29'(%)"'"F%–  %java.lang.Exception

;'7(A,%)(69,3("'(%+&A9/&+,5(0(R%,02&'"%('%0('&,%7(%/+('A(/("%:d'&%d0&R%('7(A&%7(%9'%,++,U%"06+&%(%0(2(@R%&++"+(%7(%('/96R%&6A$=F%D5(I5SE65H5(:(7:><H5$%

–  %java.lang.Error ;'7(A,%/+"50&2(%+&0,@8(%,0%A,+(A,2&'6"%7&00,%A0,))&%"%,0%V9'3("',2&'6"%7&00,%2,AAI(',%

8(+69,0&%B,8,%:&)$%'"6%&'"91I%2&2"+U=R%&%8,%A"')(7&+,6"%(++&A9/&+,5(0&F%/&+A(k%;8;(V(C5(I5SE656:$%

•  Q,%/,+"0,%G&AA&3("'&J%i%/&+k%)/&))"%+(V&+(6,%,%&'6+,25&$%

Page 12: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(K(I8>5(>8;8U(

•  P"(AIj%E;R:II:A=8;:(V(E;(877:S8R%/9k%A"'6&'&+&%7,@%"%7&d'(+&%2&6"7($%

•  H9#&%0&%&AA&3("'(%7&d'()A"'"%9'%2&6"7"%getMessage()%AI&%+&)@69()A&%(0%2&)),11("%7h&++"+&%,))"A(,6"%

•  40A9'&%&AA&3("'(%7&d'()A"'"%7&(%A,2/(%7,@%:,7%&)&2/("R%bytesTransferred%('%InterruptedIOException=%AI&%7,''"%,06+&%('V"+2,3("'(R%9@0(%/&+%1&)@+&%0,%)(69,3("'&$%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(K(I8>5(W56:U(\'%2&6"7"%AI&%/")),%1&'&+,+&%9'h&AA&3("'&%7&8&%)8"01&+&%9',%7(%m9&)6&%79&%,3("'(F%•  7:><6:(@R:II:A=8;:R%A"'%9'%A")6+9#"%try / catch "//9+&%•  6=@5;I=56@5(:>?@=I=H59:;H:(5@@R:>H:6;8%7&0%2&6"7"R%7&0&1,'7"'&%('%/+,@A,%0,%

1&)@"'&%,7%,06+($%%E&%)A&10(&%m9&)6,%)&A"'7,%)6+,7,R%(0%2&6"7"%C:D:%('7(A,+&%m9,0&%&AA&3("'&%/9k%G9)A(+&J%7,%&))"R%A"'%0,%A0,9)"0,%throws

47%&)&2/("R%9'%2&6"7"%AI&%)8"01,%9',%A"'8&+)("'&%)6+('1,b'92&+"R%5;A=IXY(7:><6:(@5(&E9B:648695H%ZI:?<8;((

/9k%7&A(7&+&%7(%6=@5;I=56@5(5@@R:>H:6;8F%

public int readInteger(String s) throws NumberFormatException {

return Integer.parseInt(s); }

Può sollevare un’eccezione

Non la gestisce, la rilancia all’esterno

Page 13: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(C:[;=6:(;E8D:(:II:A=8;=(

!,6"%AI&%9'h&AA&3("'&%i%9'%'"+2,0&%"11&#"R%i%/"))(5(0&F%

•  C:[;=6:(;E8D=(<?=(C=(:II:A=8;:%7&d'&'7"%'9"8&%A0,))(%

•  7:;:656:(:II:A=8;=.7,00h('6&+'"%7(%/+"/+(%2&6"7($%

P&+%7&d'(+&%9'%'9"8"%@/"%7(%&AA&3("'&%5,)6,%$%&'()%*+',*'+-.,*/0,11%.AI&%&)6&'7,%0,%A0,))&%5,)&%Exception

:"%9',%7&00&%)9&%)"#"A0,))(=>%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(K(@5;I=56:(:II:A=8;=(E9//"'(,2"%AI&%(0%2&6"7"%readInteger%7&55,%G+&)@69(+&%&++"+&J%'&0%A,)"%('%

A9(%(0%'92&+"%7,%A"'8&+@+&%)(,%2,11("+&%7(%YXX$%Qh&AA&3("'&%7,%0,'A(,+&%i%IllegalArgumentException

P&+%)"00&8,+&%:1&'&+,+&=%9'h&AA&3("'&F%•  ?6=95(>=(I6:5(@R877:S8(:II:A=8;:%7,%0,'A(,+&%

•  ?8=(@8(>=(@5;I=5%A"'%0h()6+93("'&%throw

public int readInteger(String s) throws NumberFormatException, IllegalArgumentException {

int x = Integer.parseInt(s); if (x>100) throw new IllegalArgumentException();

return x; }

Page 14: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(K(@5;I=56:(:II:A=8;=(E9//"'(,2"%AI&%(0%2&6"7"%readInteger%7&55,%G+&)@69(+&%&++"+&J%'&0%A,)"%('%A9(%(0%

'92&+"%7,%A"'8&+@+&%)(,%2,11("+&%7(%YXX$%Qh&AA&3("'&%7,%0,'A(,+&%i%IllegalArgumentException

P&+%)"00&8,+&%:1&'&+,+&=%9'h&AA&3("'&F%•  ?6=95(>=(I6:5(@R877:S8(:II:A=8;:%7,%0,'A(,+&%

•  ?8=(@8(>=(@5;I=5%A"'%0h()6+93("'&%throw

public int readInteger(String s) throws NumberFormatException, IllegalArgumentException {

int x = Integer.parseInt(s); if (x>100) throw new IllegalArgumentException();

return x; }

Questa è l’eccezione che può essere sollevata da parseInt

Importante non confondere: •  la clausola throws che dichiara che un metodo rilancia all’esterno un’eccezione •  l’istruzione throw che solleva un’eccezione

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(:>:6I=A=8(

^+&,+&%9',%A0,))&%/&+%0,%A"'8&+)("'&%)6+('1,b'92&+"%('6&+"$%Q,%A"'8&+)("'&%7&8&%&))&+&%0(2(6,6,%,00h('6&+8,00"%%n[YXR%YXoR%'&0%A,)"%(0%

'92&+"%)(,%V9"+(%7,00h('6&+8,00"%7&8&%&))&+&%0,'A(,6,%0h&AA&3("'&%IllegalArgumentException.

;0%A")6+9#"+&%7&00,%A0,))&%7&8&%0,'A(,+&%69#&%0&%&8&'69,0(%&AA&3("'(%AI&%7&8"'"%&))&+&%A,#9+,6&%7,0%main$%

;0%/,+,2&6+"%7,%A"'8&+@+&%7&8&%&))&+&%7,6"%('%('1+&))"%,0%main$%

Page 15: 1.ide eccezioni - Unife

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(>8@EA=8;:(

^+&"%0,%A0,))&%&%(0%A")6+9#"+&$%

public class Esercizio1 {

/** Il costruttore. */ public Esercizio1(String[] args) throws

NumberFormatException, IllegalArgumentException {

String numero = args[0]; int num = Integer.parseInt(numero); if((num<-10) || (num>10)) throw new IllegalArgumentException(“Fuori dall’intervallo"); System.out.println("Numero: " + num); }

e%e%e%e%%

*'3-"%&'$(0!+!(.%3(,/(*+$,-../()$($&'%34!11%(-'%&'%(%(*%3+$2$()$(3%'%(%(,/3/(!..,$1!2$/&%(

@:(:II:A=8;=(P(>8@EA=8;:(^+&"%(0%2,('%:,00h('6&+'"%7&00,%A0,))&=$%

… … … /** * @param args the command line arguments */ public static void main(String[] args) {

try { Esercizio1 oggetto = new Esercizio1(args); } catch(NumberFormatException e1) { System.out.println("Format Exception 1: "+e1.getMessage()); } catch(IllegalArgumentException e2) { System.out.println("Format Exception 2: "+e2.getMessage()); }

}

} //fine della classe