J'ai besoin d'avance. J'envoie une requête HTTP GET et j'analyse la réponse HTML, si la réponse HTML (chaîne html) consiste en une sous-chaîne, je veux envoyer à l'application cliente, (application WPF) un message d'erreur/d'avertissement.WPF, gérer avec message d'erreur et d'avertissement
Dans ma solution, si la chaîne html consiste en une sous-chaîne je lance une nouvelle exception, c'est stupide, quelle solution convient à ce problème?
Codeest ici:
private bool SendRp(string postData)
{
bool result = false;
const string parameters = @"&lok=1&rpI=3";
string htmlStringResult = HttpPostReq(
new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PokecUrl.Rp, Account.SessionId, parameters)), postData);
try
{
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("is is empty"))
{
throw new ArgumentException("ID is empty!");
}
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("id does not exist"))
{
throw new ArgumentException("ID does not exist.");
}
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("blocked"))
{
throw new WebException("Your ID is blocked!");
}
if (!htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("message was send"))
{
Match match = Regex.Match(htmlStringResult, @"\bhs=\w{15}\b");
if (match.Success)
{
result = true;
}
else
{
throw new Exception("Some problem");
}
}
return result;
}
catch (Exception exception)
{
throw exception;
}
}
Je comprends le problème est à jeter des exceptions. Pourquoi c'est un problème? –