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. General Programming
  3. C#
  4. Types of exceptions

Types of exceptions

Scheduled Pinned Locked Moved C#
question
2 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    hello is there any way to determine what exception has been thrown ? i have a try and catch block catching Exception all the time, but id like to know what type of Exception is thrown for an object that throws one, so i know what to catch.

    J 1 Reply Last reply
    0
    • L Lost User

      hello is there any way to determine what exception has been thrown ? i have a try and catch block catching Exception all the time, but id like to know what type of Exception is thrown for an object that throws one, so i know what to catch.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      The documentation should tell you what exceptions to expect, but you can get the name by doing the following

      catch(Exception e) {
      string name = e.GetType().Name;
      Console.WriteLine("Exception: {0}", name);
      }

      Or just take the catch out altogether and the framework will catch it, in the description it should give the name of the exception. James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

      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