mardi 23 juin 2020

Is it possible to use a method throwing an exception in an if statement condition? c#

so I am trying to error handle my code and so far this is what I have:

date = GetDate(); 
if(date.throws_exception())
{
// would it be possible to make a condition for where you can say if date throws exception?
}

string GetDate()
{
    try
    {
        .
        . 
        .
        return date;
    }
    catch(Exception ex)
    {
        throw new Exception();
    }
}

What I am wondering is it would be possible for the if condition, can you say:

if(date throws exception)

Aucun commentaire:

Enregistrer un commentaire