What happens if you don't handle exceptions?

Are exceptions really important? Are they worth the time spent handling them when you have tons of complexities in the logic? Yes, they are super important. Let's explore what will happen if you don't take care of exceptions. When an exception is triggered, if no code handles it the exception goes to the system runtime.

Furthermore, when the system runtime faces an exception, it just terminates the program. So, now you understand why you should handle exceptions. If you fail to do this, your application might break down in the middle of running. I am sure you personally don't like programs that crash while you are using them, so we have to be careful about writing exception-free software. Let's look at an example of what happens during system runtime if the exception is not handled:

Using system;

class LearnException {
public static void Main()
{
int[] a = {1,2,3,4};
for (int i=0; i<10; i++)
{
Console.WriteLine(a[i]);
}
}
}

If we run this code, then the first four times that it is run, it will perform perfectly and print some numbers from one to four. But after that, it will throw an exception of IndexOutOfRangeException and the system runtime will terminate the program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.173.242