try
AllocateSomeMemory(X);
except
ShowAWarning;
finally
if Assigned(X) then
FreeMemory(X);
end;