丟擲異常
當發生異常時,你的程式碼可以並且經常應該丟擲異常。
public void WalkInto(Destination destination)
{
if (destination.Name == "Mordor")
{
throw new InvalidOperationException("One does not simply walk into Mordor.");
}
// ... Implement your normal walking code here.
}