int foo () throws Exception
{
try
{
return 0;
}
catch (Exception e)
{
bar (); // error
}
}
void bar () throws Exception
{
throw new Exception ();
}
< /code>
Dies schlägt fehl
Der Compiler erkennt also nicht, dass die Balken auf keinen Fall die Ausnahme auswirft.
Ich denke darüber nach (return null - selbst das kann nie passieren - aber macht den Compiler glücklich).int foo () throws Exception
{
try
{
return 0;
}
catch (Exception e)
{
bar ();
return 0; // ok now for the compiler
}
}
< /code>
Ich bin mir nicht sicher, ob das eine Schönheit ist. Irgendwelche anderen Ideen dazu, Best Practice?
Sagen Sie dem Compiler, dass es ohne Ausnahme keine Möglichkeit gibt? ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post