using DesafioAlura01;
//1
using (HttpClient client = new HttpClient())
{
try
{
string resposta = await client.GetStringAsync("https://www.cheapshark.com/api/1.0/deals");
Console.WriteLine(resposta);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//2
try
{
Console.WriteLine("A: ");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("B: ");
int b = int.Parse(Console.ReadLine());
int rep = a / b;
Console.WriteLine(rep);
}
catch (DivideByZeroException)
{
Console.WriteLine("Erro: Na Matematica nao é possivel divisão por 0");
}
catch (Exception ex)
{
Console.WriteLine($"Temos um problema: {ex.Message}");
}
// 3
try
{
List<int> list = new List<int>() { 1, 2, 5, 6 };
Console.WriteLine($"Numero: {list[7]} ");
}
catch (Exception ex)
{
Console.WriteLine($"Erro: {ex.Message}");
}
// 4
try
{
Classe objetoNulo = null;
objetoNulo.Metodo();
}
catch (NullReferenceException ex)
{
Console.WriteLine($"Erro: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Erro: {ex.Message}");
}