Skip to content

Instantly share code, notes, and snippets.

@AleeRojas
Last active December 19, 2015 10:09
Show Gist options
  • Save AleeRojas/5938670 to your computer and use it in GitHub Desktop.
Save AleeRojas/5938670 to your computer and use it in GitHub Desktop.
Manejo de excepciones - Clases: Jueves 4 Jul
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int x=0, y, resultado, sw=0;
do //valida que el x sea numerico, si se ingresa una letra se vuelve a pedir x
{
try
{
Console.Write("\n ingrese un numero: ");
x = Convert.ToInt32(Console.ReadLine());
sw = 1;
}
catch (System.Exception a)
{
Console.WriteLine(a.Message);
}
} while (sw == 0);
do
{
try
{
Console.Write("\n Ingrese otro número: ");
y = Convert.ToInt32(Console.ReadLine());
}
catch (System.Exception e)
{
y = 0;
Console.Write(e.Message);
}
} while (y <= 0);
try
{
resultado = x / y;
Console.WriteLine("la division es {0}", resultado);
}
catch (System.Exception a)
{
Console.WriteLine(a.Message);
}
finally
{
Console.Write("####Presione una tecla para salir####");
Console.ReadLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment