-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
52 lines (44 loc) · 1.36 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
namespace exepciones
{
class NegativeIntegerException:Exception
{
public NegativeIntegerException():base("No se pueden capturar enteros negativos")
{
}
}
class Program
{
static void Main(string[] args)
{
int valor ;
Console.WriteLine("Ingresa tu edad:");
try {
string captura=Console.ReadLine();
valor=int.Parse(captura);
Console.WriteLine("En diez años tendras {0}",valor+10);
}
catch (Exception) {
Console.WriteLine("Formato incorrecto");
}
Console.ReadKey();
Console.WriteLine("Ahora captura un entero positivo");
try{
int valor2 =int.Parse(Console.ReadLine());
if(valor2<0)
{
throw new NegativeIntegerException();
}
Console.WriteLine("El numero entero es:{0}",valor2);
}
catch(Exception e){
Console.WriteLine("Hubo un error");
Console.WriteLine(e.Message);
}
finally{
Console.WriteLine("Fin del programa");
}
Console.ReadKey();
}
}
}