I started learning Java and I got confused about the necessity of try-catch blocks in some cases.
Let's say I have the following in my code:
System.out.println(args[0]);
If I don't have any arguments, I get the following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Main.main ...
But I wondered why do I need a try-catch block, with e.printStackTrace()
in it, if the output will be the same as above and I also could identify the problem?