Eccezioni concluse

This commit is contained in:
La Programmatrice Verde 2025-05-16 14:58:43 +02:00
parent 16f1dea942
commit 83df6fb174
9 changed files with 13 additions and 8 deletions

View File

@ -3,9 +3,9 @@
class Program { class Program {
static void Main(string[] args) { static void Main(string[] args) {
int scelta = 0; int scelta = 0;
double input = 0; int input = 0;
bool eccezione; bool eccezione;
int[] array = null; int[] array;
do { do {
@ -53,7 +53,7 @@ class Program {
Console.Write("Inserire un numero: "); Console.Write("Inserire un numero: ");
eccezione = false; eccezione = false;
try { try {
input = Convert.ToDouble(Console.ReadLine()); input = Convert.ToInt32(Console.ReadLine());
} }
catch (FormatException) { catch (FormatException) {
Console.WriteLine("Numero non valido"); Console.WriteLine("Numero non valido");
@ -87,19 +87,21 @@ class Program {
Console.ReadKey(); Console.ReadKey();
} }
static double Divisione(double input) { static double Divisione(int input) {
Random r = new Random(); Random r = new Random();
bool eccezione; bool eccezione;
double ritorno = 0; double ritorno;
do { do {
int numero = r.Next(0, 4);
eccezione = false; eccezione = false;
try { try {
ritorno = input / r.Next(0, 4); ritorno = input / numero;
} }
catch (DivideByZeroException) { catch (DivideByZeroException) {
Console.WriteLine("Impossibile dividere per 0."); Console.WriteLine("Impossibile dividere per 0.");
Pausa(); Pausa();
eccezione = true; eccezione = true;
ritorno = double.NaN;
} }
} while (eccezione); } while (eccezione);
return ritorno; return ritorno;
@ -132,6 +134,9 @@ class Program {
Pausa(); Pausa();
eccezione = true; eccezione = true;
} }
catch (IndexOutOfRangeException e) {
Console.WriteLine(e.Message);
}
} }
while (eccezione); while (eccezione);
} }

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("eccezioni_1")] [assembly: System.Reflection.AssemblyCompanyAttribute("eccezioni_1")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0dc3eed65f04928e028a1afc17f4bc8f367f78bd")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+16f1dea94221582c4d8b3ad11e57771f328fe1eb")]
[assembly: System.Reflection.AssemblyProductAttribute("eccezioni_1")] [assembly: System.Reflection.AssemblyProductAttribute("eccezioni_1")]
[assembly: System.Reflection.AssemblyTitleAttribute("eccezioni_1")] [assembly: System.Reflection.AssemblyTitleAttribute("eccezioni_1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
ee7e98605e9c5564468cd86c1b1c002f51995b579fee2b845d8a36b5f951a60b 48a3fed5e6086b9afebbe353b2777958bf4a496d106ab6a3b2c1f2232e423364

Binary file not shown.

Binary file not shown.

Binary file not shown.