Re-Throwing Exceptions
When an exception is caught in a catch block, the exception is considered to have been processed and code execution continues as normal. In some situations it is useful to catch the exception but still have it thrown to be caught again. For example, a method may catch all exceptions so that they can be logged and then re-throw the exception to be handled appropriately by the calling function.
When an exception is thrown explicitly using the syntax previously discussed, a new exception object is constructed. This exception object contains only the basic information set by the programmer; information such as the StackTrace property of the original exception is lost. To re-throw the exception and retain this additional information, the throw command is used without specifying an exception object. This is achieved using the following syntax:
The following example code demonstrates how this syntax can be used. For simplicity, the methods called are not defined so this code cannot be directly executed.
What is the difference between Server.Transfer and Server.Execute?
Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in ASP.NET).
When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control is'nt returned to the calling page).
In both the cases, the URL in the browser remains the first page url (does'nt refresh to the new page URL) as the browser is'nt requested to do so.