In a code like this
public static void Sub()
{
Console.WriteLine("Ile liczb chcesz odjąć?");
RetryPoint1:
try
{
int liczby = Convert.ToInt32(Console.ReadLine());
int[] cyfry = new int[liczby];
Console.WriteLine("Będziesz odejmować " + liczby + " liczb");
for (int i = 0; i < liczby; i++)
{
RetryPoint2:
try
{
Console.WriteLine("Wpisz " + (i + 1) + " liczbę");
cyfry[i] = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("Nie liczba!");
goto RetryPoint2;
}
}
int wynik = cyfry[0];
for (int i = 1; i < liczby; i++)
{
wynik = wynik - cyfry[i];
}
Console.WriteLine("Wynik to " + wynik);
}
catch
{
Console.WriteLine("Nie liczba!");
goto RetryPoint1;
}
}
there are two points where same exception(not int as user input) can occur. Is there some way to use retry point as variable that changes depending on when this error happened? Is it even a "valid" way of doing things in this case? Once can imagine that those try catches could start nesting quickly if there were more points within one function where the same exception could happen. I know I could put next try catch below for better readeability, but if there's same exception occurting every time, isn't there some more "right" way to handle it, with just one try catch?