In the previous example we have learnt how to handle exceptions at constructor level in C#.net. Now i am going to explain can we use try block with out catch block in CSharp.Net.
Explanation: We can use try block with out catch block by declaring finally block which is syntactically correct in C#.net. This is one of the best c#.net Interview Question
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
try
{
int i = 0, j = 1, result;
Console.WriteLine("this is try block");
}
//catch(Exception ex)
//{
// Console.WriteLine(ex.Message);
//Console.WriteLine("this is Catch block");
//}
finally
{
Console.WriteLine("this is finally block");
Console.Read();
}
}
}
}
If you have any queries or suggestions, please feel free to ask in comments section.
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.