| | |
Constructor overloading problem
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 0
Hi all... I have a problem with constructor overloading in VB.NET and, I know how to solve it, but want to know the best way to do it... so here is the problem.
I have two manually created constructors in a class, like this...
and everything goes fine... until I try to do error catching like this
then, it says that, for the constructor with 2 parameters, the call to the other constructor has to be the first instruction to call... but that's not possible if I want to catch the errors produced by the first constructor (if I move the Me.New(param1) outside the Try then every error thrown by the first constructor will not be catched.
I know that if I create a function (for example _New()) and overload this one, then, from the constructors I can just call the function and everything is solved (no Me.New() called), but I don't know if this is the correct way to go.
Thanks in advance and sorry for my english (Im spanish)
I have two manually created constructors in a class, like this...
VB.NET Syntax (Toggle Plain Text)
Public Sub New(param1 As String) ... End Sub Public Sub New(param1 As String, param2 as String) Me.New(param1) ... End Sub
VB.NET Syntax (Toggle Plain Text)
Public Sub New(param1 As String) Try ... Catch ex As Exception Throw New Exception(...) End Try End Sub Public Sub New(param1 As String, param2 as String) Try Me.New(param1) ... Catch ex As Exception Throw New Exception (...) End Try End Sub
I know that if I create a function (for example _New()) and overload this one, then, from the constructors I can just call the function and everything is solved (no Me.New() called), but I don't know if this is the correct way to go.
Thanks in advance and sorry for my english (Im spanish)
VB.NET Syntax (Toggle Plain Text)
Public Sub New(param1 As String, param2 as String) Me.New(param1) Try ... Catch ex As Exception Throw New Exception (...) End Try End Sub
i think this will be enough , since the code of Me.New(param1) will be executed first , so u will catch the errors produced by the first constructor , right ?
"give only what u willing to receive "
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
VB.NET Syntax (Toggle Plain Text)
Public Sub New(param1 As String, param2 as String) Me.New(param1) Try ... Catch ex As Exception Throw New Exception (...) End Try End Sub
i think this will be enough , since the code of Me.New(param1) will be executed first , so u will catch the errors produced by the first constructor , right ?
![]() |
Similar Threads
- operator - (minus) overloading problem (C++)
- overloading problem (C++)
- GUId Greif! (Java)
- Need help understanding what to do (C++)
Other Threads in the VB.NET Forum
- Previous Thread: datagrid grouping question
- Next Thread: OledbConnection.getschema
Views: 2662 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml





