on E: EIdHTTPProtocolException do begin if E.ErrorCode = 401 then x := E.ErrorMessage else raise; end;