i need to manage exceptions how can i ?
-
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.
-
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.
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)
-
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)
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
-
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
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)
-
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)
ok man i can found it it's sqlclient.* but that i c that i sould make catch for each exception !!!! is this right ?
-
ok man i can found it it's sqlclient.* but that i c that i sould make catch for each exception !!!! is this right ?
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)
-
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)
thanks man i got the msg i'll start writing but i think i have to write southand of lines
-
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.
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 )
-
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 )
so man can u give me an example of error handeling where there is more than one exception thanks