Retrieving teh source of an error

  • Thread starter Thread starter Michel Vanderbeke
  • Start date Start date
M

Michel Vanderbeke

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
 
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
 
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
 
Back
Top