这是什么意思 [英] What's this meaning

查看:71
本文介绍了这是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub HandlerExample()
      Dim intX As Integer
      Dim intY As Integer
      Dim intZ As Integer
      intY = 0
      intX = 5
      ' First Required Error Statement.
      Try
          ' Cause a "Divide by Zero"
          intZ = CType((intX \ intY), Integer)
          ' Catch the error.
      Catch objA As System.DivideByZeroException
          Try
              Throw (New Exception("0 as divisor", objA))
          Catch objB As Exception
              Messagebox.Show(objB.Message)
              Messagebox.Show(objB.InnerException.Message)
              Messagebox.Show(objB.TargetSite.Name)
          End Try
      Catch
          Messagebox.Show("Caught any other errors")
      Finally
          Messagebox.Show(Str(intZ))
      End Try
  End Sub




问题是为什么我们应该在另一个内部的Try块中使用Try块在另一个...等中? 我了解基本知识,但我不认识其他人?
您能向我解释一下Try子块的工作原理吗?




The question is why we should use Try block inside another Try Block inside another one ...etc ??
I understand the base block but i don''t know the others ?
Can you explain to me the the working of sub-Try Block ?

推荐答案

有时需要嵌套错误处理.但是,这种特殊情况似乎很愚蠢.在这种情况下,不需要嵌套的尝试/捕获".如果catch中的代码可能引发异常并且您有充分的理由来捕获它,则需要嵌套的Try/Catch.
There is sometimes a need for nested error handling. However, this particular case seems silly. There is no need for a nested Try/Catch in this scenario. You would need a nested Try/Catch if the code in the catch might throw an exception and you have a good reason to catch it.




它说明了如何使用try catch捕获各种错误.
在第一个try catch中,程序员将引发DivideByZeroException异常.因此它被捕获在
Hi,

It is explaining how you can catch different kinds of error with try catch.
In the first try catch, the programmer throw a DivideByZeroException exception. so it is catched on
Catch objA As System.DivideByZeroException.

上(否则它被捕获在

( otherwise it is catched on

Catch        
 Messagebox.Show("Caught any other errors")

)

现在,在该捕获中(DevideByZeroException程序员抛出了另一个常规异常.因此,它被捕获在

)

now in this catch (DevideByZeroException programmer throw another general exception. so it is catched in

Catch objB As Exception



Final块确保将执行代码



The Finally block makes sure that the code

Messagebox.Show(Str(intZ)) 

.


这篇关于这是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆