Click here to Skip to main content
15,892,746 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Disable Try/Catch Pin
Luc Pattyn15-Feb-08 11:01
sitebuilderLuc Pattyn15-Feb-08 11:01 
GeneralRe: Disable Try/Catch Pin
Paul Conrad15-Feb-08 12:43
professionalPaul Conrad15-Feb-08 12:43 
GeneralException information detail Pin
cstrader23215-Feb-08 5:27
cstrader23215-Feb-08 5:27 
GeneralRe: Exception information detail Pin
Luc Pattyn15-Feb-08 6:05
sitebuilderLuc Pattyn15-Feb-08 6:05 
GeneralRe: Exception information detail Pin
cstrader23215-Feb-08 6:22
cstrader23215-Feb-08 6:22 
GeneralRe: Exception information detail Pin
cstrader23215-Feb-08 6:32
cstrader23215-Feb-08 6:32 
GeneralRe: Exception information detail Pin
Luc Pattyn15-Feb-08 7:30
sitebuilderLuc Pattyn15-Feb-08 7:30 
GeneralRe: Exception information detail Pin
Luc Pattyn15-Feb-08 7:22
sitebuilderLuc Pattyn15-Feb-08 7:22 
Hi,

proper exception handling is a rather complex matter. I'll try and give some of the
basics here:

1.
you should not catch an exception and then ignore it, since that would destroy useful
information, needed to remedy an exceptional situation; every exception should either
be solved (e.g. an alternative way gets attempted), or the problem should be
signalled to the caller (through a "result" return value, a new exception, or by
not catching it in the first place).

2.
normally you should catch an exception where you are able to deal with it,
and that often is pretty close to where it happens.

Example: if you have a mathematical algorithm and suddenly get a divide-by-zero,
it does not make sense to have that catched several method levels above it, since
at that level the caller would not be aware of the algorithm, what a zero-divide
would be, and how it should be remedied. Instead, you should catch it locally, and
try to organize things such that the method fails gracefully.

3.
it is often wise to include a specification on exceptions when specifying a
method or a library; exception handling is a basic part of the contract.
(Java enforces this, .NET does not; there are pros and cons tho).

4.
It does not hurt to have a top-level try-catch (that's in the static main method itself);
it should NEVER fire in production code, it's main purpose is to help the developer notice
all the exceptions that are lacking a local try-catch.
If it fires in production code, it halts the app, which never looks good; but it should
show all available info (hence ToString), and urge the user to send that to the developer.

5.
not all exceptions are easily noticed and dealth with; there are special measures to
deal with exceptions in constructors, in background threads, in remote objects,
in native code, etc.

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: Exception information detail Pin
cstrader23215-Feb-08 7:45
cstrader23215-Feb-08 7:45 
GeneralRe: Exception information detail Pin
Luc Pattyn15-Feb-08 7:49
sitebuilderLuc Pattyn15-Feb-08 7:49 
GeneralRe: Exception information detail Pin
cstrader23215-Feb-08 10:15
cstrader23215-Feb-08 10:15 
GeneralRe: Exception information detail Pin
supercat918-Feb-08 6:16
supercat918-Feb-08 6:16 
GeneralRe: Exception information detail Pin
Luc Pattyn18-Feb-08 9:06
sitebuilderLuc Pattyn18-Feb-08 9:06 
GeneralNET 1.1 SMTP problem : "The transport failed to connect to the server." [modified] Pin
Stortman15-Feb-08 4:07
Stortman15-Feb-08 4:07 
GeneralRe: NET 1.1 SMTP problem : "The transport failed to connect to the server." Pin
Dave Kreskowiak15-Feb-08 4:30
mveDave Kreskowiak15-Feb-08 4:30 
GeneralRe: NET 1.1 SMTP problem : "The transport failed to connect to the server." Pin
Stortman15-Feb-08 5:32
Stortman15-Feb-08 5:32 
GeneralRe: NET 1.1 SMTP problem : "The transport failed to connect to the server." Pin
Dave Kreskowiak15-Feb-08 5:49
mveDave Kreskowiak15-Feb-08 5:49 
GeneralRe: NET 1.1 SMTP problem : "The transport failed to connect to the server." Pin
Stortman15-Feb-08 11:06
Stortman15-Feb-08 11:06 
GeneralRe: NET 1.1 SMTP problem : "The transport failed to connect to the server." Pin
Stortman15-Feb-08 13:58
Stortman15-Feb-08 13:58 
GeneralOpening VS2005 Project in VS2008 Pin
plural15-Feb-08 3:11
plural15-Feb-08 3:11 
GeneralRe: Opening VS2005 Project in VS2008 Pin
Dave Kreskowiak15-Feb-08 4:26
mveDave Kreskowiak15-Feb-08 4:26 
GeneralRe: Opening VS2005 Project in VS2008 Pin
plural15-Feb-08 4:37
plural15-Feb-08 4:37 
QuestionTop most question? Pin
Benny_Lava15-Feb-08 2:35
Benny_Lava15-Feb-08 2:35 
GeneralRe: Top most question? Pin
Dave Kreskowiak15-Feb-08 4:23
mveDave Kreskowiak15-Feb-08 4:23 
GeneralRe: Top most question? Pin
Luc Pattyn15-Feb-08 6:08
sitebuilderLuc Pattyn15-Feb-08 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.