Saturday, April 26, 2025

C# - Exceptions - Try..Catch..Finally

using System;

namespace LearnCS
{
    class Program
    {      
        static void Main(string[] args)
        {

            try
            {
                char[] characters = { 'A', 'B', 'C' };
                Console.WriteLine(characters[200]);
            }
            catch (Exception e) {
                Console.WriteLine("Alarm General !!!");
                Console.WriteLine("------------------------------------------");
                Console.WriteLine("Details: " + e.Message);
            }            

        }
    }
}
using System;

namespace LearnCS
{
    class Program
    {      
        static void Main(string[] args)
        {
            try
            {
                char[] characters = { 'A', 'B', 'C' };
                Console.WriteLine(characters[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Alarm General !!!");
                Console.WriteLine(e.Message);
            }
            finally {
                Console.WriteLine();
                Console.WriteLine("####################################");
                Console.WriteLine("I Will Be Printed No Matter What !!!");
                Console.WriteLine("####################################");
            }
        }
    }
}

 

NEXT >

INDEX

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...