Catch Build Error

jspaarg

Member
Joined
Aug 20, 2005
Messages
8
Programming Experience
10+
Catch Build Error: SOLVED

Greetings.

I am brand new to this forum but have been writing software for over 20 years.
I started writing Vb.Net apps about one year ago.
My apologies if this is not the proper forum for this post.

I have an RS232 class with the line
Catch Ex As Exception

This comes from a file that was given to me by someone who has done .net for about three years. He got it from the internet somewhere.

I use this file in multiple solutions and have never, until now, had a problem.

One of the solutions that uses this file, gives the following build error:

(593): 'Catch' cannot catch type 'exception' because it is not 'System.Exception' or a class that inherits from 'System.Exception'.

This does not occur in any other solution that uses this file. I know that I am missing something obvious, but I have checked all my resources, drivers, inheritances, and imports, and nothing seems to be different from other solutions where this line works.

Can anyone help?

Thanks.
 
Last edited:
Thanks for the thought. I do not have a reference for Crystal Reports and am not using it in the solution. I am also not using it in any other solution where this code works.

Unfortunately in this environment I suffer from using other people's code and not knowing exactly what it is doing.


The real problem seems to originate with this error

[...]RS232.vb(163): Overload resolution failed because no accessible 'New' can be called with these arguments:
'Protected Sub New(info As System.Runtime.Serialization.SerializationInfo, context As System.Runtime.Serialization.StreamingContext)': Value of type 'String' cannot be converted to 'System.Runtime.Serialization.SerializationInfo'.
'Protected Sub New(info As System.Runtime.Serialization.SerializationInfo, context As System.Runtime.Serialization.StreamingContext)': Value of type 'exception' cannot be converted to 'System.Runtime.Serialization.StreamingContext'.
'Public Sub New(message As String, innerException As System.Exception)': Value of type 'exception' cannot be converted to 'System.Exception'.

The code that this references is:
VB.NET:
[size=2]
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Class[/color][/size][size=2] CIOChannelException : [/size][size=2][color=#0000ff]Inherits[/color][/size][size=2] ApplicationException
 
[/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2]([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] Message [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2])
 
[/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].New(Message)
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2]([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] Message [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] InnerException [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception)
 
[/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].New(Message, InnerException)
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Class
 
[/color][/size]

The failure is the line with the InnerException parameter.
 
Well, i think you should consider a rule No. 1 "never catch an exception that you don't know how to handle". With other words: Never catch an exception without performing some action upon the exception. If you don't know what the code is standing for and app still performing its job in that case simply ignore it. However, try catch statement is not Obligatory.


Cheers ;)
 
Obviously good advice about not catching exceptions.

However, the question is not what to do with the exception.

The question is "Why can I use the EXACT same RS232 source file in four solutions and it compiles cleanly in three of them and not the fourth?"
 
It would be helpful to see the code that threw the exception.
It's obvious that there is much code left out here. By the last line of the error message "'Public Sub New(message As String, innerException As System.Exception)': Value of type 'exception' cannot be converted to 'System.Exception'." it seems that you have written a class called 'exception' ?
 
Thanks for the reply.

There is no code throwing the exception because this is a compile time, not a run time error. (Unless I don't understand the question).

You are correct in that there is a class called CIOCHannelException.
As I said in a prior post, this is code that was given to me and has always worked. The person who gave it to me did not write it either.

The error indiciates that there is some kind of problem with overloading the function, but why does it only happen in one solution (and for that matter, this exact same code builds properly on another computer).

I know there is something basic, or there is a piece of information that I am not providing, but I am new to this .NET thing.

Thanks for any thoughts.
 
The problem came from a third party driver that had hijacked the "exception" keyword.

Updated the driver and everything works.
 
Back
Top