如何从finally子句中抛出catch子句中捕获的异常?

Cod*_*lue 2 java exception try-catch-finally

是否可以在不使用其他变量的情况下找出catch子句中捕获的异常,然后从finally子句中再次抛出它?

public void exceptionalFunction() throws Exception
 {
    try
     {
         // exception causing code
     }
    catch (TypeAException e)
     {
        // exception specific logic
     }
    catch (TypeBException e)
     {
         // exception specific logic        
     }
    catch (TypeCException e)
     {
        // exception specific logic        
     }
    finally
     {
         // throw the exception that was caught, if one was caught. 
     }
 }
Run Code Online (Sandbox Code Playgroud)

tib*_*tof 6

不是没有使用额外的变量.如果不使用其他变量,则只能在异常特定逻辑之后再次抛出异常:

catch (TypeAException e)
{
    // exception specific logic 
    throw e;       
}
catch (TypeBException e)
{
    // exception specific logic 
    throw e;       
}
catch (TypeCException e)
{
    // exception specific logic 
    throw e;       
}
Run Code Online (Sandbox Code Playgroud)