Can we use multiple finally blocks inside the method?
Yes, you can write the multiple finally block inside the method. For every try block, you can have finally.
Is it possible to keep finally inside the try block?
Yes, It is possible to keep finally inside the try block. Shown in above example.
Is it possible to keep multiple catch block for the try block?
Yes, Is is possible. You can have multiple catch blocks associated with a try block, but only a single catch block can ever handle your exception.
Can we write try block without catch block?
No, It’s not allowed to write an try block without catch/finally block. you have to write one of the blocks either catch or finally.
Can we write try block only with finally block?
Yes, You can write the try only with finally block.
- Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.