Tutorial by Examples

Structure: Try 'Your program will try to run the code in this block. 'If any exceptions are thrown, the code in the Catch Block will be executed, 'without executing the lines after the one which caused the exception. Catch ex As System.IO.IOException 'If an exception occurs w...
You can create a custom exception and throw them during the execution of your function. As a general practice you should only throw an exception when your function could not achieve its defined functionality. Private Function OpenDatabase(Byval Server as String, Byval User as String, Byval Pwd as S...
You can use Try..Catch to rollback database operation by placing the rollback statement at the Catch Segment. Try 'Do the database operation... xCmd.CommandText = "INSERT into ...." xCmd.ExecuteNonQuery() objTrans.Commit() ...
Although Catch ex As Exception claims that it can handle all exceptions - there are one exception (no pun intended). Imports System Static Sub StackOverflow() ' Again no pun intended StackOverflow() End Sub Static Sub Main() Try StackOverflow() Catch ex As Exception ...
Generally most of the exceptions are not that critical, but there are some really serious exceptions that you might not be capable to handle, such as the famous System.StackOverflowException. However, there are others that might get hidden by Catch ex As Exception, such as System.OutOfMemoryExceptio...

Page 1 of 1