E
E
embiid2021-12-15 13:06:56
C++ / C#
embiid, 2021-12-15 13:06:56

How will throw work?

try
{
}
catch(CustomException  t)
{
}
catch(Exception ex)
{
    throw;
    throw ex;
    throw new MyEx(ex);
}
finally {}


What will be the program call, how will throw react? And why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-12-15
@vabka

They won’t work here in any way, because the try block is empty.
But if there were, then:
If CustomException was thrown, the exception would be suppressed.
If any of the others fell out, it would be forwarded further without changes.
Execution would not reach these lines. What by the way any IDE talks about

throw ex;
throw new MyEx(ex);

Well, the finally block would still be guaranteed to be executed after all the catches were processed, but before the fall.
61b9e108af4d3560067099.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question