473,574 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Handling

Hey. I'm still not experienced at error handling, and I need to know if
Try.. Catch blocks are meant to be used to handle errors in your own app, ie
bugs. Or, are they only for external things like db problems, file not
found. Any websites or books on error handling, real-life examples, would be
appreciated.

Tks

Justin Dutoit

Nov 20 '05 #1
10 2729
"Justin Dutoit" <an**@anon.co m> wrote in
news:#D******** *****@tk2msftng p13.phx.gbl:
Hey. I'm still not experienced at error handling, and I need to know
if Try.. Catch blocks are meant to be used to handle errors in your
own app, ie bugs. Or, are they only for external things like db
problems, file not found. Any websites or books on error handling,
real-life examples, would be appreciated.


Try Catch is used to handle ANY error... could be DB error, your own
errors, etc.

As the name of the syntax implies, it is used to catch errors : )

--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2
Could you point me to some detailed examples, including how the errors are
handled? I know you log them in the db, or windows event log, but what
else....

Tks
Justin
"Lucas Tam" <RE********@rog ers.com> wrote in message
news:Xn******** *************** ***@140.99.99.1 30...
"Justin Dutoit" <an**@anon.co m> wrote in
news:#D******** *****@tk2msftng p13.phx.gbl:
Hey. I'm still not experienced at error handling, and I need to know
if Try.. Catch blocks are meant to be used to handle errors in your
own app, ie bugs. Or, are they only for external things like db
problems, file not found. Any websites or books on error handling,
real-life examples, would be appreciated.


Try Catch is used to handle ANY error... could be DB error, your own
errors, etc.

As the name of the syntax implies, it is used to catch errors : )

--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 20 '05 #3
"Justin Dutoit" <an**@anon.co m> wrote in
news:OD******** ******@TK2MSFTN GP10.phx.gbl:
Could you point me to some detailed examples, including how the errors
are handled? I know you log them in the db, or windows event log, but
what else....


Text File. Display message box. It doesn't really matter. It's up to you
how to handle the error.

Some people even call another function and process the data a different
way.

Think of the Try, Catch as a big if statement, with the condition being the
error.
--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #4
Thanks, but I mean an example of a situation, say, editing a record in a db.
What can go wrong and what might the code look like please?

Tks
Justin
"Lucas Tam" <RE********@rog ers.com> wrote in message
news:Xn******** *************** ***@140.99.99.1 30...
"Justin Dutoit" <an**@anon.co m> wrote in
news:OD******** ******@TK2MSFTN GP10.phx.gbl:
Could you point me to some detailed examples, including how the errors
are handled? I know you log them in the db, or windows event log, but
what else....
Text File. Display message box. It doesn't really matter. It's up to you
how to handle the error.

Some people even call another function and process the data a different
way.

Think of the Try, Catch as a big if statement, with the condition being

the error.
--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 20 '05 #5
this is a simple example :-

private sub errHandler()

Dim x As Integer

Dim y As Integer

Dim z As Integer

x = 10

y = 0

Try

'we are going to divide and integer by zero to generate an error

z = x / y

Catch ex1 As System.Overflow Exception

MessageBox.Show ("Over Flow")

Finally

MessageBox.Show ("finally")

End Try

this code will throw the error.

-------

Nov 20 '05 #6
Justin,
Catch blocks are meant to be used to handle errors in your own app, ie
bugs. Or, are they only for external things like db problems, file not
found.<<

If I understand your question correctly, here is my tuppence worth:

1. Try Catch are used to handle 'Exceptions'
2. Exceptions as 'Unexpected' events that prevent a method/function from
performing its nomral task.
3. Expections should not be confused for Application Rule Failure
(Validation). You except the validation to fail and you would know how to
handle it.
4. So, 'Your' methods always should return an Error Code to indicate success
or failure.
5. Catch an exception ONLY when you know how to handle it.
6. For predictability, it is a good idea to install a global Expception
Handler to handle all Unhandled exceptions.

Well about how exactly to handle Exceptions, when you are using the services
of an external dotnet object(some thing written by others), the author will
normally publish the Exceptions that the object is programmed to throw. You
handle those exceptions in your function( only if you know how to deal with
it).

Vipul,

Are your sure z = x / y will cause an Exception ? Dotnet uses IEEE
Arithmetic standard and I would be surprised if divide by zero is thrown as
an exception in VB.net.

"vipul DotNet" <yp***@hotmail. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.phx.gbl... this is a simple example :-

private sub errHandler()

Dim x As Integer

Dim y As Integer

Dim z As Integer

x = 10

y = 0

Try

'we are going to divide and integer by zero to generate an error

z = x / y

Catch ex1 As System.Overflow Exception

MessageBox.Show ("Over Flow")

Finally

MessageBox.Show ("finally")

End Try

this code will throw the error.

-------


Nov 20 '05 #7
Cor
Justin,
Hey. I'm still not experienced at error handling, and I need to know if
Try.. Catch blocks are meant to be used to handle errors in your own app, ie bugs. Or, are they only for external things like db problems, file not
found. Any websites or books on error handling, real-life examples, would be appreciated.

If you try this little example, I think you see it.
\\\
Dim a As Integer
Try
a = CInt("a")
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try
/////
I hope this helps a little bit.
Cor
Nov 20 '05 #8
nice chap ,
yes this code will throw an error and it will be caught under the
system.Overflow Exception

"Nice Chap" <Ni******@Plasm aDyne.com> wrote in message
news:#O******** ******@TK2MSFTN GP11.phx.gbl...
Justin,
Catch blocks are meant to be used to handle errors in your own app, ie
bugs. Or, are they only for external things like db problems, file not
found.<<

If I understand your question correctly, here is my tuppence worth:

1. Try Catch are used to handle 'Exceptions'
2. Exceptions as 'Unexpected' events that prevent a method/function from
performing its nomral task.
3. Expections should not be confused for Application Rule Failure
(Validation). You except the validation to fail and you would know how to
handle it.
4. So, 'Your' methods always should return an Error Code to indicate

success or failure.
5. Catch an exception ONLY when you know how to handle it.
6. For predictability, it is a good idea to install a global Expception
Handler to handle all Unhandled exceptions.

Well about how exactly to handle Exceptions, when you are using the services of an external dotnet object(some thing written by others), the author will normally publish the Exceptions that the object is programmed to throw. You handle those exceptions in your function( only if you know how to deal with it).

Vipul,

Are your sure z = x / y will cause an Exception ? Dotnet uses IEEE
Arithmetic standard and I would be surprised if divide by zero is thrown as an exception in VB.net.

"vipul DotNet" <yp***@hotmail. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.phx.gbl...
this is a simple example :-

private sub errHandler()

Dim x As Integer

Dim y As Integer

Dim z As Integer

x = 10

y = 0

Try

'we are going to divide and integer by zero to generate an error

z = x / y

Catch ex1 As System.Overflow Exception

MessageBox.Show ("Over Flow")

Finally

MessageBox.Show ("finally")

End Try

this code will throw the error.

-------



Nov 20 '05 #9
thanks Nice Chap for the warning !

vipul

"Nice Chap" <Ni******@Plasm aDyne.com> wrote in message
news:#B******** ******@TK2MSFTN GP10.phx.gbl...
Well, here is a word of caution, if you used 'Single' or 'Double' as the LHS of a quotient assignment( in most of the cases you would), dot net DOES NOT THROW AN EXCEPTION for divide by zero. You have to use IsInfinity* functions to test the value for your range. This is in line with IEEE Arithmetic. But If you used an integral data type as LHS dotnet does throw an exception.

"vipul DotNet" <yp***@hotmail. com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
nice chap ,
yes this code will throw an error and it will be caught under the
system.Overflow Exception

"Nice Chap" <Ni******@Plasm aDyne.com> wrote in message
news:#O******** ******@TK2MSFTN GP11.phx.gbl...
Justin,

>>Catch blocks are meant to be used to handle errors in your own app, ie bugs. Or, are they only for external things like db problems, file not
found.<<

If I understand your question correctly, here is my tuppence worth:

1. Try Catch are used to handle 'Exceptions'
2. Exceptions as 'Unexpected' events that prevent a method/function from performing its nomral task.
3. Expections should not be confused for Application Rule Failure
(Validation). You except the validation to fail and you would know how to handle it.
4. So, 'Your' methods always should return an Error Code to indicate

success
or failure.
5. Catch an exception ONLY when you know how to handle it.
6. For predictability, it is a good idea to install a global Expception Handler to handle all Unhandled exceptions.

Well about how exactly to handle Exceptions, when you are using the

services
of an external dotnet object(some thing written by others), the author

will
normally publish the Exceptions that the object is programmed to
throw. You
handle those exceptions in your function( only if you know how to deal

with
it).

Vipul,

Are your sure z = x / y will cause an Exception ? Dotnet uses IEEE
Arithmetic standard and I would be surprised if divide by zero is
thrown as
an exception in VB.net.

"vipul DotNet" <yp***@hotmail. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.phx.gbl...
> this is a simple example :-
>
> private sub errHandler()
>
> Dim x As Integer
>
> Dim y As Integer
>
> Dim z As Integer
>
> x = 10
>
> y = 0
>
> Try
>
> 'we are going to divide and integer by zero to generate an error
>
> z = x / y
>
> Catch ex1 As System.Overflow Exception
>
> MessageBox.Show ("Over Flow")
>
> Finally
>
> MessageBox.Show ("finally")
>
> End Try
>
> this code will throw the error.
>
> -------
>
>
>
>
>



Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3260
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error handling within classes. Just hoping to hear some programmer's thoughts on error handling.
12
6657
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that assert could be used to start an interactive debugger automatically. How do I realize that on a Linux machine using gcc?
21
4389
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a...
3
2841
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a easy and reusable way of handling all errors in a program. The VB 6 coding examples I have seen there has always been error handling code in each...
4
1923
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I haven't placed error handling code). When I run my app from the IDE, the unhandled errors are caught by the error handling code in my Sub Main...
1
9915
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement below executes as expected, and were I to replace "print" with something meaningful I could do some useful error handling. The second statement just...
10
2276
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise...
1
2244
by: pob | last post by:
>From a form I have some code that calls 4 modules frmMain 1 mod 2 mod 3 mod 4 mod If mod 1 experiences an error the error handling works fine within mod 1 and writes out the error to a table, but the other modules still get
35
3753
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks gets about 3 or so. It also gets very awkward in nested loops, where you want to check for normal loop processing in the loop condition, not...
0
11564
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you...
0
7738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8077
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7828
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3755
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.