I am writing an error handler that tried to fix or mitigate the error. If the mitigation code errors I want to ignore the mitigation error and raise the original error. This is the error handler I have written.
try
// <Normal code>
raise Exception.Create('Original error');
except
on E: Exception do
try
// <Attempt to mitigate the error> // If successful will continue without an exception
raise Exception.Create('Mitigation error');
except
raise E; // Mitigation failed, raise original error
end;
end;
The above does not work. When the mitigation exception triggers the application descends into a chaos of invalid pointers.
Does anyone know how to do this?
try..except? The issue is that you useraise Eto re-raise the original exception. This is what you should do instead:on E: Exception do if not TryMitigate(E) then raise;.