What is the purpose of using try, catch blocks?
3 answers
No, this is not a replacement for an if and then a block, it serves a completely different purpose. The purpose of try, catch block is to try to do something that might not work and throw an exception (for example, read a file from disk, but the file might be missing, etc.). Once you find the exception, you can deal with it.
try {
riskyOperation();
catch (ExpectedException) {
handleException();
}
+11
a source to share