Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is there a way to retrieve the number of the exception that is thrown by a Try Catch?

 

It give the message but sometimes it's helpfull to have the number too...

 

 

Thanks

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
  • Administrators
Posted

Depends on the exception some like a SQLException contain an error number property based on the error code raised by SQL, but most do not.

Unlike VB6 where the error number was all you had to go on to determine the problem exceptions are more OO - the exception itself denotes the type of error (InvalidCastException, OverflowException, DivideByZeroException etc.)

 

Could you give a code sample of where you would need such a number - there may be an alternate way of solving the problem.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I got this need when my app thrown me an exception saing something like this: "The application could not start...".

 

The big problem is that I'm Portuguese and this exception was in Portuguese and so I had some dificulty finding any resourses about it on the Net.

 

If the exception had a number, no matter what language your OS is, that number would always remain the same...

 

Althow I successfully trasnslated the exception and found what it was searching on Google.

 

 

Thanks

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
  • Administrators
Posted

The type of exception never changes between languages either though. The following snippet may give a better idea.

 

Dim i As Integer
Try
i = Integer.Parse(TextBox1.Text)
Catch ex As FormatException
      'handle invalid data type here

Catch ex As OverflowException
'handle nuber being too large here
Catch ex As Exception
'anything else here
MessageBox.Show(ex.ToString)
End Try

 

and you could always get the underlying exception type as a string for logging with something similar to

MessageBox.Show(GetType(Exception).ToString())

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I know that the type of the exceptions doesn't change, but the message displayed to the user its OS dependant and so, if the SO its in Portuguese the message its in the same language.

 

I belive this overlaped their minds... They only wanted to hide the supposable unecessary info but the error number is quite the only way anyone can search it around the net...

 

When you gave me that code with all those Try/Catch, those exceptions don't have all possible exception types... specially if the exception was thrown by th OS itself...

 

Either way... I got the point and already solved my problem translating the exception...

 

 

Thanks !

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
  • Administrators
Posted (edited)

Surely you can search on the exception name though - rather than the error message itself.

Agreed my sample doesn't have handlers for all exceptions - I just used the ones that made most sense for the likey errors to occur in that given situation, as for exceptions raised by the OS itself not too sure what you mean there could you give an example?

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

This "need" apear to me about a week ago with an error just like this: "A aplicacao nao pode arrancar."... translating it's "The application couldn't start."... after this just a bunch of "0xffff0fefffx0000"... You know...

 

I can't really remember but was something related with my database. Cute isn't it? :p

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...