Error Handling
Try Catch Blocks
Open your web.config file
Set debug to true in web.config

- Add a new webform
- Type Generate an exception
- Add a button
- Double-click the button and add this code:
Dim test as string=nothing
Response.write(test.toString( ) )
This will cause an exception
Add try catch around it
Try
Dim test as string=nothing
Response.write(test.toString( ) )
Catch ex as exception
Response.write(string.concat(“An error occurred”,ex.message)
End try
Generates a generic exception
Modify it:
Try
Dim test as string=nothing
Response.write(test.toString( ) )
Catch nex as nullreferenceexception
Response.write(string.concat(“The variable was not initialized”))
Catch ex as exception
Response.write(string.concat(“An error occurred”,ex.message)
End try
Exception handling stops trying to catch once an exception is handled
Put specific handlers first
Put generic handlers last