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. How to count the error

How to count the error

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 5 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.
  • A Offline
    A Offline
    Assaf82
    wrote on last edited by
    #1

    Hello i try to count the i have in my form. i put the try and catch block, in the finally i want to count the number of error i have. or even if i don't put the try catch block how i can count the error Thanks in advance

    Assaf

    A N L 3 Replies Last reply
    0
    • A Assaf82

      Hello i try to count the i have in my form. i put the try and catch block, in the finally i want to count the number of error i have. or even if i don't put the try catch block how i can count the error Thanks in advance

      Assaf

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      i dont understand your question !!!!:confused::confused: :omg:Why you are trying to count. ?:omg: if you use counter in Finally block it always should be 1 cause while any one error occured , code directly jumped to catch block then it will go to finaly. :cool:

      Best Regards ----------------- Abhijit Jana View My CodeProject Articles "Success is Journey it's not a destination"

      1 Reply Last reply
      0
      • A Assaf82

        Hello i try to count the i have in my form. i put the try and catch block, in the finally i want to count the number of error i have. or even if i don't put the try catch block how i can count the error Thanks in advance

        Assaf

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Assaf82 wrote:

        i try to count the i have in my form.

        Count what ?

        Assaf82 wrote:

        i put the try and catch block, in the finally i want to count the number of error i have.

        Count will be incorrect as finally will be executed all the time. Declare a variable and increment it in each catch block.

        Assaf82 wrote:

        or even if i don't put the try catch block how i can count the error

        I think it's not possible. When an unhandled error occurs, application will stop execution.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        D 1 Reply Last reply
        0
        • N N a v a n e e t h

          Assaf82 wrote:

          i try to count the i have in my form.

          Count what ?

          Assaf82 wrote:

          i put the try and catch block, in the finally i want to count the number of error i have.

          Count will be incorrect as finally will be executed all the time. Declare a variable and increment it in each catch block.

          Assaf82 wrote:

          or even if i don't put the try catch block how i can count the error

          I think it's not possible. When an unhandled error occurs, application will stop execution.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

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

          use a flag variable

          A 1 Reply Last reply
          0
          • A Assaf82

            Hello i try to count the i have in my form. i put the try and catch block, in the finally i want to count the number of error i have. or even if i don't put the try catch block how i can count the error Thanks in advance

            Assaf

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, maybe this is what you want:

            int errors=0;
            foreach (... in collection) {
            try {
            ...
            } catch (Exception exc) {
            errors++;
            Console.WriteLine("Error "+errors+": "+exc.ToString());
            }
            }
            Console.WriteLine("There were "+errors+" errors");

            :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


            1 Reply Last reply
            0
            • D DharmarajNagarajan

              use a flag variable

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              DharmarajNagarajan wrote:

              use a flag variable

              It is not possible to use flag variable to count the number of error. when any one error will occer it will jump to Catch block, then directly move to finally block. so where you going to use flag !!!! Try { first here !!! } catch ( ) { if any error } Finaly { after error occured or not finaly here } so , counter is useless !!!!!

              Best Regards ----------------- Abhijit Jana View My CodeProject Articles "Success is Journey it's not a destination"

              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