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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# throw exception code format

C# throw exception code format

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 3 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.
  • E Offline
    E Offline
    edel_ong
    wrote on last edited by
    #1

    Hello, how can i make a C# function throw a certain exception? Thanks very much!

    C S 2 Replies Last reply
    0
    • E edel_ong

      Hello, how can i make a C# function throw a certain exception? Thanks very much!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you didn't write the function (i.e. if you can't change the source code), you cannot change what exceptions it throws, all you can do is throw whatever seems appropriate to you based on what the function returns. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • E edel_ong

        Hello, how can i make a C# function throw a certain exception? Thanks very much!

        S Offline
        S Offline
        Sean89
        wrote on last edited by
        #3

        If you have written the function, to throw an exception you do this: private void someFunction() { throw (new Exception()); } But adjust the type of exception accordingly. Is that what you wanted? Hope that helps.

        S 1 Reply Last reply
        0
        • S Sean89

          If you have written the function, to throw an exception you do this: private void someFunction() { throw (new Exception()); } But adjust the type of exception accordingly. Is that what you wanted? Hope that helps.

          S Offline
          S Offline
          Sean89
          wrote on last edited by
          #4

          'throw (new Exception());' must be inside the function block: openFileClicked() { throw (new Exception()); }

          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