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. Break program flow

Break program flow

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 4 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.
  • D Offline
    D Offline
    D Shen
    wrote on last edited by
    #1

    Hi, My application will collect different parameters from user input. Once the "Execute" button is pressed, the parameters will be passed to related methods for exection. I try to figure out how to stop the program flow (not close the application but ask input for missing parameters)if I find some parameters missing (something like Exit() in VB) Can someone please tell me how to do this? Thanks!!:omg:

    N P 2 Replies Last reply
    0
    • D D Shen

      Hi, My application will collect different parameters from user input. Once the "Execute" button is pressed, the parameters will be passed to related methods for exection. I try to figure out how to stop the program flow (not close the application but ask input for missing parameters)if I find some parameters missing (something like Exit() in VB) Can someone please tell me how to do this? Thanks!!:omg:

      N Offline
      N Offline
      Nnamdi Onyeyiri
      wrote on last edited by
      #2

      get the seperatly called messages to throw an exception if a parameter they need is missing, then use the try/catch loop in Execute to catch the exceptions, and do something about it. :)


      :suss: Email: theeclypse@hotmail.com   URL: http://www.onyeyiri.co.uk
      :suss:"All programmers are playwrights and all computers are lousy actors."

      D 1 Reply Last reply
      0
      • D D Shen

        Hi, My application will collect different parameters from user input. Once the "Execute" button is pressed, the parameters will be passed to related methods for exection. I try to figure out how to stop the program flow (not close the application but ask input for missing parameters)if I find some parameters missing (something like Exit() in VB) Can someone please tell me how to do this? Thanks!!:omg:

        P Offline
        P Offline
        Paul Riley
        wrote on last edited by
        #3

        Application.Exit() ? Paul

        D 1 Reply Last reply
        0
        • N Nnamdi Onyeyiri

          get the seperatly called messages to throw an exception if a parameter they need is missing, then use the try/catch loop in Execute to catch the exceptions, and do something about it. :)


          :suss: Email: theeclypse@hotmail.com   URL: http://www.onyeyiri.co.uk
          :suss:"All programmers are playwrights and all computers are lousy actors."

          D Offline
          D Offline
          D Shen
          wrote on last edited by
          #4

          Thank you. Since I am new to C#, can you please show me how to throw an exception and catch it? Thanks!

          N 1 Reply Last reply
          0
          • P Paul Riley

            Application.Exit() ? Paul

            D Offline
            D Offline
            David Stone
            wrote on last edited by
            #5

            He said: D Shen wrote: not close the application but ask input for missing parameters ;-PNnamdi told him how to do it. David Stone But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*. Shog9

            P 1 Reply Last reply
            0
            • D David Stone

              He said: D Shen wrote: not close the application but ask input for missing parameters ;-PNnamdi told him how to do it. David Stone But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*. Shog9

              P Offline
              P Offline
              Paul Riley
              wrote on last edited by
              #6

              Yeah, misread the question completely. Such is life. I'm getting used to people pointing out stupid things I've said today. I swear I should go back to bed :zzz::zzz::zzz: Paul

              1 Reply Last reply
              0
              • D D Shen

                Thank you. Since I am new to C#, can you please show me how to throw an exception and catch it? Thanks!

                N Offline
                N Offline
                Nnamdi Onyeyiri
                wrote on last edited by
                #7

                there are different types of exceptions in the framework, and you can derive your own, but here is a simple way do throw and catch an exception.

                // to thow an exception
                throw new Exception("The error text here.");

                // catch an exception
                try
                {
                // This method throws an exception [as above] if something is wrong
                SomeFunction();
                }
                catch
                {
                MessageBox("There was an error with your input!");
                }

                hope that helps :)


                :suss: Email: theeclypse@hotmail.com   URL: http://www.onyeyiri.co.uk
                :suss:"All programmers are playwrights and all computers are lousy actors."

                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