Various possible combinations of try- catch- finally?
2 min readMar 25, 2023
- Whenever we are writing try block compulsory we should write catch or finally that is ‘try’ without catch or finally is invalid syntax.
- Whenever we are writing catch block compulsory we should write try block that is catch without try is invalid.
- Whenever we are writing finally block compulsory we should write try block. that is finally without try is invalid.
- In try catch finally, order is important.
- ‘try’ with multiple catch blocks Is valid but the order is important compulsory we should take from child to parent. by mistake if we are trying to take from parent to child then we will get compile time error.
- if we are defining to catch blocks for the same exception we will get compile time error.
- we can define try-catch-finally with in the try, with in the catch and with in finally blocks. Hence nesting of try-catch-finally is valid.
- For try-catch-finally curly braces are mandatory.