473,804 Members | 2,983 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 2750
"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
3274
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
6702
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
4429
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 more detailed description of what happens when an un-handled error occurs - possibly with help file...
3
2860
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 program module.
4
1941
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 routine and the error details are logged to a text file and optionally e-mailed to me for follow-up.
1
9925
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 seems to totally bail out after the error, preventing me from doing any useful error handling....
10
2298
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 it returns false. **I am not looking for comments on the usefulness of this function - it is
1
2256
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
3810
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 errors. Yes, you could put some generic exit flag in the loop condition, but when you're simply done if...
0
11604
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 start a new module, either in a form or report, or a global module, Access does not declare Option...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4292
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
3
2988
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.