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. Defining excepion

Defining excepion

Scheduled Pinned Locked Moved C#
xml
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.
  • P Offline
    P Offline
    Paolo Ponzano
    wrote on last edited by
    #1

    Hello, I just want to override the System.Exception in order to log when an exception occurrs in an XML file, for doing that I tought I sould declare a class called exception and then to do public class Exception : System.Exception { .... } but I don't know to say to code that I want to use my exception when I do catch (Exception ex) { .... } thanks Paolo

    D 1 Reply Last reply
    0
    • P Paolo Ponzano

      Hello, I just want to override the System.Exception in order to log when an exception occurrs in an XML file, for doing that I tought I sould declare a class called exception and then to do public class Exception : System.Exception { .... } but I don't know to say to code that I want to use my exception when I do catch (Exception ex) { .... } thanks Paolo

      D Offline
      D Offline
      Dennis C Dietrich
      wrote on last edited by
      #2

      You could do something like this:

      namespace MyNamespace
      {
      public class Exception : System.Exception
      {
      }

      public class Foo
      {
      public void Bar()
      {
      try {}
      catch (MyNamespace.Exception e) {}
      }
      }
      }

      However, you really should not do it like this. Instead use a self-explanatory name for your exception class that ends with Exception (just as an example: XMLProcessingException). For details on using exceptions see Class Naming Guidelines[^], Best Practices for Handling Exceptions[^] and Using User-Defined Exceptions[^]. Best regards Dennis

      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