469,609 Members | 1,182 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Retrieving teh source of an error

Hello,

When you get an error in a VB.NET program, is it possible to know what is
the origin of the error. I assume it can be VB.NET, the framework, a
database engine, the database itself (Access, SQL Server, ...).

How can you know which source has thrown the exception?
Some error messages are in English, some in my own language.

Many thanks and greetings,

Michel
Aug 10 '07 #1
2 1037
On Aug 10, 12:16 pm, "Michel Vanderbeke" <michel.vanderb...@skynet.be>
wrote:
Hello,

When you get an error in a VB.NET program, is it possible to know what is
the origin of the error. I assume it can be VB.NET, the framework, a
database engine, the database itself (Access, SQL Server, ...).

How can you know which source has thrown the exception?
Some error messages are in English, some in my own language.

Many thanks and greetings,

Michel
Try
'// Bad code here
Catch (ex as Exception)
'// Examine the variable 'ex' here to determine the problem from
'// useful properties such as StackTrace and Message etc.
End Try

Thanks,

Seth Rowe

Aug 10 '07 #2
If you are using sql server to connect to databases, you can obtain error
messages generated by sql server in the language your user is using.
Import System.threading.thread

In the connection string add Language=MyUserLanguage wher you previously
deteremined the language the user is using as follows

MyUserLanguage = CurrentThread.currentUIculture.Tostring
Set the connection string before you fill the dataset.

In the try catch block you can use
catch ex as .......
Where you can look at the list of possible values, for instance you will see
that you can catch an odbc exception
you can have several catch statements in the same try catch block each one
directed to find a different type of exception.
Try
catch exo as Oledb.oledbexception
you get oledb error info if an oledb error occurs
CatchExs as exception
you get standard exception info
end try
Some exceptions will not return localized text, others like sql server will
if you specify the Language being used.
I would create Resource files for the errors I expect, one for each language
being used and make error messages in each language so then you can use
My.resources.thenameof the Errormessagekey and the program will pick up your
localized error messages. The standard ex.message and ex.stack trace will be
in English and should not realy be shown to the user.

You can create an exception class that shows a form with texboxes for info
on Whathappened, How it affects the User, what the user can do and
additional tech info. and if you feel it necessary you can take screen shots
and mail untrapped errors to tech support.

In Vs2005 you can use the application event on untrapped error to trap these
errors, get the info to show an error form to the user anfd then get a
screen shot, and a stack trace to send to tech support. Its not that hard to
do.

HTH
Bob

"Michel Vanderbeke" <mi***************@skynet.bewrote in message
news:46***********************@news.skynet.be...
Hello,

When you get an error in a VB.NET program, is it possible to know what is
the origin of the error. I assume it can be VB.NET, the framework, a
database engine, the database itself (Access, SQL Server, ...).

How can you know which source has thrown the exception?
Some error messages are in English, some in my own language.

Many thanks and greetings,

Michel


Aug 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jimmyfo | last post: by
5 posts views Thread by Sanjay Pais | last post: by
3 posts views Thread by Bruno Vignola | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.