|
-
Jun 6th, 2005, 09:06 AM
#1
Thread Starter
Evil Genius
Exception handling????
Hi people! At the moment, I use this type of routine in VB:
VB Code:
Sub Test()
Dim obj as Object
Try
' obj.new
' obj.property
Catch ex as Exception
' handle obj exception
Finally
If not (obj is nothing) then
obj = nothing
End If
End Try
End Sub
From doing the same in this c# language, this:
Code:
void Test() {
object obj
try {
// obj.new
// obj.property
}
catch Exception ex {
// handle obj exception
}
finally {
if (obj !=null) {
obj = null
}
}
}
Generates a "Use of unassigned local variable" exception for the obj variable. It looks like my choices are:
1) To declare and set with the New() keyword, any objects, right at the top of the method - which means a performance hit as I'm not just referencing them only when I need to, or...
2) To put the calls to set the object to null within only the try block. Then if an exception's generated before this line, just leave it to the garbage collector only to clear the object from memory.
Surely this can't be right can it? I though C# was at least the same, if not more efficient than VB?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|