Why does this raise Windows Authentication and not an exception?

Okay, so after spending most of the day debugging a silly input error inside a piece of code, I'm curious as to why specific actions were thrown and not an exception.

First of all, the problem code.

Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
    Dim hl As New HyperLink
    AddHandler hl.DataBinding, AddressOf Me.BindData
    container.Controls.Add(container)
End Sub

      

The obvious problem is that we are trying to add a container to ourselves, which I was expecting to throw an exception. However, instead, it made the page ask the user for login credentials (Windows authentication in the browser).

Does anyone have an idea why this is the case and why the exception or something else hasn't happened?

EDIT

The reason for the question is that this error renders the page useless and asks for Windows logon and does NOT throw exceptions or any other exceptions.

+1


source to share


2 answers


Where do you expect the exception to happen? There is no reason within this code to throw an exception. As counterintuitive as it would be to nest a control in a control, it is still valid. It won't paint very well, and if the paint / paint layer doesn't know for sure about nesting it could cause a loop / infinity. But that won't happen here, but during layout / paint.



+1


source


Controls are something that can be arbitrarily nested; anything that has a control can have a bunch of other controls (I'm sure the reason is obvious). At the same time, there is nothing "wrong" with adding a reference to a given object to a collection of such objects within itself. Although redundant, it is not exclusive.



+1


source







All Articles