I am working on a project where I need to perform two different operation.
I have a finally block in my main controller method.
My question is, can I have more than two finally, for example:
class test
{
X()
{
try
{
//some operations
}
finally
{
// some essential operation
}
}
//another method
Y()
{
try
{
//some operations
}
finally
{
// some another essential operation
}
}
}
so,is it possible?
Yes, you can have as many
try - catch - finallycombination you want but they all should be correctly formatted. (i.e syntax should be correct)In your example, you’ve written correct syntax and it’ll work as expected.
You can have in following way:
OR