Share throw exception vb.net

bichhue357

New member
## Ném ngoại lệ trong vb.net

* [Ngoại lệ là gì?]
* [Cách ném một ngoại lệ trong vb.net] (https://docs.microsoft.com/en-us/do...ng-guide/exceptions/how-to-throw-an-exception)
* [Cách xử lý một ngoại lệ trong VB.NET] (https://docs.microsoft.com/en-us/do...g-guide/exceptions/how-to-handle-an-exception)

### ví dụ

`` `VBNet
'Ném một ngoại lệ nếu giá trị nhỏ hơn 0
Nếu giá trị <0 thì
Ném ngoại lệ mới ("Giá trị phải lớn hơn hoặc bằng 0")
Kết thúc nếu

'Xử lý một ngoại lệ bằng cách in thông báo lỗi vào bảng điều khiển
Thử
'Mã có thể ném một ngoại lệ
Bắt EX làm ngoại lệ
Console.WriteLine (Ex.Message)
Kết thúc thử
`` `

### hashtags

* #vb.net
* #Exceptions
* #Error xử lý
* #Programming
* #tutorial
=======================================
## Throw Exception in VB.NET

* [What is an Exception?](https://docs.microsoft.com/en-us/dotnet/api/system.exception?view=net-6.0)
* [How to Throw an Exception in VB.NET](https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/exceptions/how-to-throw-an-exception)
* [How to Handle an Exception in VB.NET](https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/exceptions/how-to-handle-an-exception)

### Examples

```vbnet
' Throw an exception if the value is less than 0
If value < 0 Then
Throw New Exception("Value must be greater than or equal to 0")
End If

' Handle an exception by printing the error message to the console
Try
' Code that might throw an exception
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
```

### Hashtags

* #vb.net
* #Exceptions
* #Error Handling
* #Programming
* #tutorial
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top