if else in combo with try catch

This topic contains 2 replies, has 2 voices, and was last updated by  michael glenn 2 years, 10 months ago.

  • Author
    Posts
  • #19717

    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

    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

    michael glenn
    Participant

    thank you...exactly what im looking for.

You must be logged in to reply to this topic.