Lesson 31 of 34
Exceptions: பிழைகளைக் கையாளுதல்Exceptions: Handling Errors
10 min 30 XP
Program இயங்கும்போது பிழை (exception) வந்தால் அது நின்றுவிடும். try உள்ளே ஆபத்தான code-ஐ வைத்து, catch மூலம் பிழையைப் பிடித்து கையாளலாம். finally எப்போதும் இயங்கும்.
When an error (exception) happens while a program runs, it crashes. Put risky code inside try and handle the error in catch. finally always runs.
Example: edit me and press Run
Press Run to see the result here.throw மூலம் நாமே ஒரு exception-ஐ எழுப்பலாம், உதாரணமாக தவறான மதிப்பு வந்தால்.
You can raise an exception yourself with throw, for example when a method receives a bad value.
Example: edit me and press Run
Press Run to see the result here.Checked exceptions (IOException போன்றவை) compile நேரத்திலேயே கையாள வேண்டும்; unchecked (RuntimeException) அப்படி அல்ல. இந்த வேறுபாடு interview-ல் கேட்கப்படும்.
Checked exceptions (like IOException) must be handled at compile time; unchecked ones (RuntimeException) need not be. Interviews love this difference.