I'm wondering if there is any capability to re-throw an existing exception (in a catch clause), within an expression switch case? Please take a look at the code example:
try
{
// Some code...
}
catch (Exception ex)
{
return ex switch
{
ExceptionA => // return some value with expression.
ExceptionB => // return some value with expression
_ => throw ex
}
}
The code will end with the following error:
Re-throwing caught exception changes stack information
This code is for example purposes; it's clear that a statement switch case is the obvious solution
switch (ex)
{
case 1: ...
case 2: ...
default: throw;
{