Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. try to throw and catch.

try to throw and catch.

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharphelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kim Togo
    wrote on last edited by
    #1

    Was troubleshooting some code in C# and came across this: This is not the original code, but just to give an idea of what happens.

    try
    {
    Console.WriteLine("enter try catch");
    try
    {
    Console.WriteLine("enter try finally");
    throw new Exception("try-finally exception");
    Console.WriteLine("exit try finally");
    }
    finally
    {
    Console.WriteLine("finally called");
    }
    Console.WriteLine("exit try catch");
    }
    catch (Exception ex)
    {
    Console.WriteLine("exception: " + ex.Message);
    }

    Output is: enter try catch enter try finally finally called exception: try-finally exception The problem was that exit try catch was never called. I think the person that has written the code believed that a try-finally has implicit catch.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups