Throw Deyimi (Visual Basic)Throw Statement (Visual Basic)
Bir yordam içinde özel durum oluşturur.Throws an exception within a procedure.
SyntaxSyntax
Throw [ expression ]
BölümPart
expression
Oluşturulacak özel durum hakkında bilgi sağlar.Provides information about the exception to be thrown. Bir bildirimde bulunduğunda isteğe bağlı Catch
, aksi takdirde gereklidir.Optional when residing in a Catch
statement, otherwise required.
AçıklamalarRemarks
Throw
Bu ifade, yapılandırılmış özel durum işleme kodu ( Try
... Catch
) ile işleyebileceğiniz bir özel durum oluşturur. ...Finally
) ya da yapılandırılmamış özel durum işleme kodu ( On Error GoTo
).The Throw
statement throws an exception that you can handle with structured exception-handling code (Try
...Catch
...Finally
) or unstructured exception-handling code (On Error GoTo
). Throw
Bu ifadeyi, uygun özel durum işleme kodunu bulana kadar çağrı yığınını Visual Basic, kodunuzun içindeki hataları yakalamak için kullanabilirsiniz.You can use the Throw
statement to trap errors within your code because Visual Basic moves up the call stack until it finds the appropriate exception-handling code.
Throw
İfadesi olmayan bir deyim yalnızca bir Catch
deyimde kullanılabilir, bu durumda deyim deyim tarafından işlenmekte olan özel durumu yeniden oluşturur Catch
.A Throw
statement with no expression can only be used in a Catch
statement, in which case the statement rethrows the exception currently being handled by the Catch
statement.
Throw
İfade, özel durum için çağrı yığınını sıfırlar expression
.The Throw
statement resets the call stack for the expression
exception. expression
Sağlanmazsa, çağrı yığını değişmeden bırakılır.If expression
is not provided, the call stack is left unchanged. Özel durum için çağrı yığınına özelliği aracılığıyla erişebilirsiniz StackTrace .You can access the call stack for the exception through the StackTrace property.
ÖrnekExample
Aşağıdaki kod Throw
bir özel durum oluşturmak için ifadesini kullanır:The following code uses the Throw
statement to throw an exception:
' Throws a new exception.
Throw New System.Exception("An exception has occurred.")