|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
End all running code of .dllI'm writing a .dll. I'd like to know how to stop all the code running from anywhere in the solution. For example: -A class of the .dll is called from an .exe. -Function A is called from the main sub. -Function A calls Function B. -Function B calls Function C. -I need to terminate all the running code from Function C with a simple method/function. Is there an easy way to do this? Sometimes it gets very long to propagate error handling back tho the main sub when deep into functions. I get this error when writing "End": 'End' statement cannot be used in class library projects. It seems 'End' statement doesn't work in .dlls... Any ideas? JakkyTchong JakkyTch***@yahoo.com wrote:
> -A class of the .dll is called from an .exe. And that's what Exceptions are all about.> -Function A is called from the main sub. > -Function A calls Function B. > -Function B calls Function C. > -I need to terminate all the running code from Function C with a simple > method/function. > > Is there an easy way to do this? Sometimes it gets very long to > propagate error handling back tho the main sub when deep into > functions. You'll probably need a flag defined at the class level that is read by the lowest-level function. When it sees this flag being set, the method throws an Exception. The Exception is caught and handled by the top-level function, which then decides what, if anything it can do about it. Class Z Private m_bOops As Boolean = False Sub A() Try B() Catch ex As Exception Return ' or whatever End Try End Sub Sub B() C() End Sub Sub C() Do While True If m_bOops Then Throw New ApplicationException( "Boom" ) End If End Do End Sub End Class > It seems 'End' statement doesn't work in .dlls... I would suggest that End is never required.HTH, Phill W. Thanks Phill for the very useful snippet of code. That would work well
I think. Do yo know if it would be possible to do approximately the same thing using events? I don't have any experience with events at all. Would it be simple enough to implement? JakkyTchong Phill W. wrote: Show quoteHide quote > JakkyTch***@yahoo.com wrote: > > > -A class of the .dll is called from an .exe. > > -Function A is called from the main sub. > > -Function A calls Function B. > > -Function B calls Function C. > > -I need to terminate all the running code from Function C with a simple > > method/function. > > > > Is there an easy way to do this? Sometimes it gets very long to > > propagate error handling back tho the main sub when deep into > > functions. > > And that's what Exceptions are all about. > > You'll probably need a flag defined at the class level that is read by > the lowest-level function. > When it sees this flag being set, the method throws an Exception. > The Exception is caught and handled by the top-level function, which > then decides what, if anything it can do about it. > > Class Z > Private m_bOops As Boolean = False > > Sub A() > Try > B() > Catch ex As Exception > Return ' or whatever > End Try > End Sub > > Sub B() > C() > End Sub > > Sub C() > Do While True > If m_bOops Then > Throw New ApplicationException( "Boom" ) > End If > End Do > End Sub > > End Class > > > It seems 'End' statement doesn't work in .dlls... > > I would suggest that End is never required. > > HTH, > Phill W. JakkyTch***@yahoo.com wrote:
> Do yo know if it would be possible to do approximately the An event can spike a "notification" to some routine that is interested > same thing using events? I don't have any experience with events at > all. Would it be simple enough to implement? in it, but can't affect the flow of execution - you can't get out of a function by raising an event; you can by throwing an Exception. HTH, Phill W. Alright then! An Exception it will be!
Thanks a lot Phill for your help and have a great weekend! JakkyTchong Phill W. wrote: Show quoteHide quote > JakkyTch***@yahoo.com wrote: > > Do yo know if it would be possible to do approximately the > > same thing using events? I don't have any experience with events at > > all. Would it be simple enough to implement? > > An event can spike a "notification" to some routine that is interested > in it, but can't affect the flow of execution - you can't get out of a > function by raising an event; you can by throwing an Exception. > > HTH, > Phill W.
Referencing Controls created at run time.
FileListBox from VB6? Help with first VB application - Data Entry form MS VB Newbie Tutorial Check to see if a server is running Check if a Windows service running Class item not accessible because it's private... but it's not? Dataset Writing to a file opened in another class Multi-level TreeNode storing? |
|||||||||||||||||||||||