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. Visual Basic
  4. i need to manage exceptions how can i ?

i need to manage exceptions how can i ?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
9 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.
  • H Offline
    H Offline
    Hasan Jaffal
    wrote on last edited by
    #1

    I 'm making a project, and i need to make it well, so i want to manage exceptions well I mean to make a message for each error, and i want to write message in French not in English, so what I should do? I need to check data types (int - string ...) because the user can add a float in a case of integer and a string where he should enter a number... I need to check the date format because the user can use the US or the UK system dd-mm-yyyy or mm-dd-yyyy or else. I need to manage the errors by the application like the division by zero and else. Thanks for help.

    R C 2 Replies Last reply
    0
    • H Hasan Jaffal

      I 'm making a project, and i need to make it well, so i want to manage exceptions well I mean to make a message for each error, and i want to write message in French not in English, so what I should do? I need to check data types (int - string ...) because the user can add a float in a case of integer and a string where he should enter a number... I need to check the date format because the user can use the US or the UK system dd-mm-yyyy or mm-dd-yyyy or else. I need to manage the errors by the application like the division by zero and else. Thanks for help.

      R Offline
      R Offline
      Rupesh Kumar Swami
      wrote on last edited by
      #2

      hi lord, write ur code between following block Try 'Write your code here Catch ex as exception msgbox ex.message End try from above code u can able to handle any type of exception. Now call following function at keypress event of Textbox so the user must be enter proper value // For accept only Text & white Space pass "e" ( one of the argument of keypress event) to this function Public Sub CheckPressedKeyText(ByVal key As System.Windows.Forms.KeyPressEventArgs) If Not (Char.IsControl(key.KeyChar) Or Char.IsLetter(key.KeyChar) Or Char.IsWhiteSpace(key.KeyChar)) Then key.Handled = True End If End Sub // For accept only numeric value with "." pass "e" ( one of the argument of keypress event) and "sender.text" to this function Public Sub CheckPressedKeyNumericWithDot(ByVal key As System.Windows.Forms.KeyPressEventArgs, ByVal str As String) If str.Contains(".") Then CheckPressedKeyNumericWithoutDot(key) Else If Not (Char.IsControl(key.KeyChar) Or Char.IsNumber(key.KeyChar) Or key.KeyChar = ".") Then key.Handled = True End If End If End Sub // For accept only numeric value without "." pass "e" ( one of the argument of keypress event) to this function Public Sub CheckPressedKeyNumericWithoutDot(ByVal key As System.Windows.Forms.KeyPressEventArgs) If Not (Char.IsControl(key.KeyChar) Or Char.IsNumber(key.KeyChar)) Then key.Handled = True End If End Sub for date, use DateTimePicker & set format property to "Custom" and then set Custom format property to ur choice.

      Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

      H 1 Reply Last reply
      0
      • R Rupesh Kumar Swami

        hi lord, write ur code between following block Try 'Write your code here Catch ex as exception msgbox ex.message End try from above code u can able to handle any type of exception. Now call following function at keypress event of Textbox so the user must be enter proper value // For accept only Text & white Space pass "e" ( one of the argument of keypress event) to this function Public Sub CheckPressedKeyText(ByVal key As System.Windows.Forms.KeyPressEventArgs) If Not (Char.IsControl(key.KeyChar) Or Char.IsLetter(key.KeyChar) Or Char.IsWhiteSpace(key.KeyChar)) Then key.Handled = True End If End Sub // For accept only numeric value with "." pass "e" ( one of the argument of keypress event) and "sender.text" to this function Public Sub CheckPressedKeyNumericWithDot(ByVal key As System.Windows.Forms.KeyPressEventArgs, ByVal str As String) If str.Contains(".") Then CheckPressedKeyNumericWithoutDot(key) Else If Not (Char.IsControl(key.KeyChar) Or Char.IsNumber(key.KeyChar) Or key.KeyChar = ".") Then key.Handled = True End If End If End Sub // For accept only numeric value without "." pass "e" ( one of the argument of keypress event) to this function Public Sub CheckPressedKeyNumericWithoutDot(ByVal key As System.Windows.Forms.KeyPressEventArgs) If Not (Char.IsControl(key.KeyChar) Or Char.IsNumber(key.KeyChar)) Then key.Handled = True End If End Sub for date, use DateTimePicker & set format property to "Custom" and then set Custom format property to ur choice.

        Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

        H Offline
        H Offline
        Hasan Jaffal
        wrote on last edited by
        #3

        hello again thanks man ... now if i used the try ... catch ex msg(ex.msg) end try i can't specify the error in meaning of: if a procedure does not exist in the DB ... or if we have division by zero how to specify my msg to show ... i want to send the folowing msg : 1- if division by zero : msgbox("Tu as fait une division par zero") 2- if connection broken : msgbox(" il y a eu une coupure de connection") u see ... i need to take in consideration some execptions thanks 4 help again

        R 1 Reply Last reply
        0
        • H Hasan Jaffal

          hello again thanks man ... now if i used the try ... catch ex msg(ex.msg) end try i can't specify the error in meaning of: if a procedure does not exist in the DB ... or if we have division by zero how to specify my msg to show ... i want to send the folowing msg : 1- if division by zero : msgbox("Tu as fait une division par zero") 2- if connection broken : msgbox(" il y a eu une coupure de connection") u see ... i need to take in consideration some execptions thanks 4 help again

          R Offline
          R Offline
          Rupesh Kumar Swami
          wrote on last edited by
          #4

          hi lord use this one for division by zero try ' write code here Catch ex As DivideByZeroException msgbox("Tu as fait une division par zero") end try & for connection broken exception , presently i have no more idea but u can handle it manually( according to where this exception may occur) try following one Catch ex As data. Catch ex As oledb Catch ex As odbc Catch ex As DataException hope this helps

          Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

          H 1 Reply Last reply
          0
          • R Rupesh Kumar Swami

            hi lord use this one for division by zero try ' write code here Catch ex As DivideByZeroException msgbox("Tu as fait une division par zero") end try & for connection broken exception , presently i have no more idea but u can handle it manually( according to where this exception may occur) try following one Catch ex As data. Catch ex As oledb Catch ex As odbc Catch ex As DataException hope this helps

            Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

            H Offline
            H Offline
            Hasan Jaffal
            wrote on last edited by
            #5

            ok man i can found it it's sqlclient.* but that i c that i sould make catch for each exception !!!! is this right ?

            R 1 Reply Last reply
            0
            • H Hasan Jaffal

              ok man i can found it it's sqlclient.* but that i c that i sould make catch for each exception !!!! is this right ?

              R Offline
              R Offline
              Rupesh Kumar Swami
              wrote on last edited by
              #6

              yes, if u want to show your own message to user (not .net generated message). otherwise it is not essential.

              Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

              H 1 Reply Last reply
              0
              • R Rupesh Kumar Swami

                yes, if u want to show your own message to user (not .net generated message). otherwise it is not essential.

                Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)

                H Offline
                H Offline
                Hasan Jaffal
                wrote on last edited by
                #7

                thanks man i got the msg i'll start writing but i think i have to write southand of lines

                1 Reply Last reply
                0
                • H Hasan Jaffal

                  I 'm making a project, and i need to make it well, so i want to manage exceptions well I mean to make a message for each error, and i want to write message in French not in English, so what I should do? I need to check data types (int - string ...) because the user can add a float in a case of integer and a string where he should enter a number... I need to check the date format because the user can use the US or the UK system dd-mm-yyyy or mm-dd-yyyy or else. I need to manage the errors by the application like the division by zero and else. Thanks for help.

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

                  First of all, code that's wrapped in hundreds of try/catch statements is bad code. You should first check, for example, if you may be about to divide by zero. You should use int.tryparse,double.tryparse, etc, to see if a string contains the value type you expect. You should allow casting from double to int, unless you have special reasons not to. An exception should be, well, exceptional. It shouldn't be something that you expect to happen in normal flow.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  H 1 Reply Last reply
                  0
                  • C Christian Graus

                    First of all, code that's wrapped in hundreds of try/catch statements is bad code. You should first check, for example, if you may be about to divide by zero. You should use int.tryparse,double.tryparse, etc, to see if a string contains the value type you expect. You should allow casting from double to int, unless you have special reasons not to. An exception should be, well, exceptional. It shouldn't be something that you expect to happen in normal flow.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                    H Offline
                    H Offline
                    Hasan Jaffal
                    wrote on last edited by
                    #9

                    so man can u give me an example of error handeling where there is more than one exception thanks

                    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