Exception handling
In VB, exception handling is primarily accomplished using structured error-handling constructs, such as Try...Catch...Finally blocks, rather than inheritance. However, it’s worth noting that exception handling in VB does involve classes and inheritance but in a different manner.
VB uses the Exception
class, which is a base class for all exceptions in the .NET Framework, to handle errors and exceptions. The Exception
class has several derived classes representing specific types of exceptions, such as SystemException
and ApplicationException
. When an exception occurs, VB throws an object of one of these derived exception classes, which you can then catch and handle using Try...Catch...Finally blocks.
Here’s an example demonstrating exception handling in VB using Try...Catch...Finally:
Sub Main() Try Dim n1 As Integer = 20 Dim...