Sample Exceptions in C#
Error Types- Syntax Error: Compile type error is syntax error.
- Exception error: Run time error is exception error.
- Logical error: If you make a mistake in a program such as use incorrect logic then show an error then it is called a logical error. “A logical error occurs when an application compiles and runs properly but does not produce the expected result.”
- “An exception is termed as an abnormal condition by an application during its exception.”
- An Exception is an error that occurs during program execution; exceptional situations arise when an operation can't be completed normally.
- When an exception occurs in and application the system throws an error.
Categorized of exception
- System.Exception
- Pre-Defined for use:
System.SystemException - User Defined for Use:
System.SystemApplicationException
- An Exception handling is the process of providing an alternative path of execution of program, when the application is unable to execute as desired.
An System.IO.IOException exception is thrown when you try to access an illegal stream object.
- If the denominator is zero then an integer division operation throws the “System. DivideByZeroException” exception.
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Exception2
- {
- class Test
- {
- static int Zero = 0;
- static void AFunction()
- {
- try
- {
- int j = 22 / Zero;
- }
- // this exception doesn't match
- catch (DivideByZeroException e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine("In AFunction()");
- }
- //class Program
- //{
- public static void Main()
- {
- try
- {
- AFunction();
- }
- // this exception doesn't match
- catch (ArgumentException e)
- {
- Console.WriteLine("ArgumentException {0}", e);
- }
- Console.ReadKey();
- }
- //}
- }
- }
So friends, these are a few comments that will help you with samples of exceptions in C#. The next time I will put some more interesting comments, thank you. I hope this is helpful for you. Enjoy :).
:)
:)
:)
Thanks for visiting
Krishna Rajput
singhkrishna512@gmail.com
No comments:
Post a Comment
Please Comment Your Valuable Feedback....