Kivételek kezelése

This commit is contained in:
Kovács Rudolf committed 2026-11-03 13:59:31 +01:00
1 parent eb560ac912
commit c5a502262d
4 files changed
+90

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Kivetelek/Kivetelek.csproj" />
</Solution>
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+48
View File
@@ -0,0 +1,48 @@
namespace Kivetelek
{
internal class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Adjon meg egy számot!");
int szam = Convert.ToInt32(Console.ReadLine());
Sportolo sportolo = new Sportolo { Nev="Elek",Magassag=78};
try
{
throw new ArgumentException("Hibás argumentum!");
}
catch (ArgumentException ex)
{
Console.WriteLine("Hibás argumentum!");
}
}
catch (FormatException ex)
{
Console.WriteLine("Számot kell megadni!");
}
catch (OverflowException ex)
{
Console.WriteLine("A megadott érték túl nagy!");
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
finally
{
Console.WriteLine("Ami itt van az mindig lefut.");
}
Console.WriteLine("Megyünk tovább...");
}
}
}
+29
View File
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Kivetelek
{
public class Sportolo
{
public string Nev { get; set; }
private int magassag;
public int Magassag {
get { return magassag; }
set
{
if (value>100)
{
magassag = value;
}
else
{
throw new ArgumentException("Hibás magasság érték!");
}
}
}
}
}