Try Catch and Finally

Discussion in 'ASP .Net' started by Alfredo, Aug 11, 2005.

  1. Alfredo

    Alfredo Guest


    I have question, i debug this code:

    'Some operations
    Response.Redirect("Page 1")
    Response.Redirect("Page 2")
    end try

    I am getting an error but always Page 2 is loaded. Why?


    Alfredo Barrientos
    Alfredo, Aug 11, 2005
    1. Advertisements

  2. Alfredo

    Marina Guest

    Because the Finally block always executes no matter if the try part
    succeeded or not.
    Marina, Aug 11, 2005
    1. Advertisements

  3. Alfredo

    Curt_C [MVP] Guest

    try a throw or break, but the idea is that the FINALLY will always fire.
    Also, look at the Response.Redirect() it has some extra props to stop
    execution, perhaps that will work for you.
    Curt_C [MVP], Aug 11, 2005
  4. The way the Catch statement works is:

    1) TRY run the code in the Try part

    2) If an exception occurs, run code in the Catch Part.

    3) FINALLY , run code in the Finally part.

    So no matter what happens, that finally will always run.
    Grant Merwitz, Aug 11, 2005
  5. Alfredo

    Guest Guest

    Guest, Aug 11, 2005
  6. Try
    'Some operations

    Response.Redirect("Page 2")

    Response.Redirect("Page 1")

    End Try()
    Marc Robitaille, Aug 11, 2005
  7. What they all said.


    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Everybody picks their nose,
    But some people are better at hiding it.
    Kevin Spencer, Aug 11, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.