Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 20, 2014 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/7c18d0c7e0ff67aefb1d to your computer and use it in GitHub Desktop.
Save Fhernd/7c18d0c7e0ff67aefb1d to your computer and use it in GitHub Desktop.
Control de excepcionese en bloque try...catch.
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");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment