if else in combo with try catch

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of michael glenn michael glenn 2 years, 1 month ago.

  • Author
    Posts
  • #19717
    Profile photo of michael glenn
    michael glenn
    Participant

    im looking for examples of if else statements combined with try catch statements. im not finding much in my google searches
    is such a thing legal?

  • #19718
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Certainly. Both of those constructs can contain any other language elements inside the curly braces. For example:

    try
    {
        if ($something) {
            Do-Something
        }
        else
            Do-SomethingElse
        }
    }
    catch
    {
        # Handle error
    }
    
    # Or:
    
    if ($something)
    {
        try
        {
            Do-Something
        }
        catch
        {
            # Handle error
        }
    }
    else
    {
        try
        {
            Do-SomethingElse
        }
        catch
        {
            # Handle error
        }
    }
    
  • #19719
    Profile photo of michael glenn
    michael glenn
    Participant

    thank you...exactly what im looking for.

You must be logged in to reply to this topic.