using System;
namespace Articulos.Cap04
{
public sealed class ControlDEExcepciones
{
public static int Dividir (int a, int b)
{
if ( b == 0)
{
throw new DivideByZeroException();
}
return a / b;
}
public static void Main()
{
int num1 = 7;
int num2 = 0;
int resultado;
try
{
resultado = Dividir(num1, num2);
Console.WriteLine ("\nLa división de {0} entre {1} es igual a {2}\n", num1, num2, resultado);
}
catch (DivideByZeroException e)
{
Console.WriteLine ("\nIntento de división entre 0\n");
}
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIEFydGljdWxvcy5DYXAwNAp7CiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIENvbnRyb2xERUV4Y2VwY2lvbmVzCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyBpbnQgRGl2aWRpciAoaW50IGEsIGludCBiKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKCBiID09IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHRocm93IG5ldyBEaXZpZGVCeVplcm9FeGNlcHRpb24oKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgcmV0dXJuIGEgLyBiOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBpbnQgbnVtMSA9IDc7CiAgICAgICAgICAgIGludCBudW0yID0gMDsKICAgICAgICAgICAgaW50IHJlc3VsdGFkbzsKICAgICAgICAgICAgCiAgICAgICAgICAgIHRyeQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICByZXN1bHRhZG8gPSBEaXZpZGlyKG51bTEsIG51bTIpOwogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJcbkxhIGRpdmlzacOzbiBkZSB7MH0gZW50cmUgezF9IGVzIGlndWFsIGEgezJ9XG4iLCBudW0xLCBudW0yLCByZXN1bHRhZG8pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNhdGNoIChEaXZpZGVCeVplcm9FeGNlcHRpb24gZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJcbkludGVudG8gZGUgZGl2aXNpw7NuIGVudHJlIDBcbiIpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9