[SOLVED] Exceptions --> Checked VS Unchecked | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

[SOLVED] Exceptions --> Checked VS Unchecked

There's any good soul here to explain in a simple and comprensive way (without jargon) what is the difference between: * CHECKED Exceptions (Java) & * UNCHECKED Exceptions (C#), in a way that a newbie could understand? (in a practical sense) Thank you.

24th Dec 2021, 10:31 PM
Kiwwi# - avatar
2 Réponses
+ 2
I will try : Checked Exceptions : They are thrown (showed) at compile-time (which means when the program is compiling, before running), they are generally thrown when you try to access things of the system, not of Java (libraries and packages), the most common cases are files and SQL databases that doesn't exists (IOException and SQLException) and parse error (ParseException which is thrown for example when you try to parse a date with Date from the "I'm not a DATE!" string). Unchecked Exceptions : They are thrown when the programs run, I think the best example is a division calculator app : the user is asked to enter 2 numbers which are assigned to a and b variables, first it enters 6 and 2, the result is 3 and the app works fine, then it enters 100 and 50, the result will be 2, after that it enters 1 and 0, Java will try to run 1 / 0 but as this is impossible, it will throw an ArithmeticException while the program was running, another good example is the NullPointerException
25th Dec 2021, 12:48 AM
VCoder - avatar
+ 1
Conclusion : The difference is in their name : Checked Exceptions means errors which are checked when the code compiles, which isn't the case of Unchecked ones which are thrown after the compilation, you can avoid both of them with the throws statement or the try-catch block
25th Dec 2021, 12:52 AM
VCoder - avatar