使用 try/catch 的优缺点 [英] advantages and disadvantages of using try/catch

查看:47
本文介绍了使用 try/catch 的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下使用try有什么优点缺点/catch?什么时候必须使用,什么时候不能使用?

I want to ask what is the advantage and disadvantages of using try/catch? and when I must use it and when I must not use it ?

推荐答案

当您在应用程序中使用某些外部控件/dll 并且不确定其功能并且不希望该外部控件中的错误停止时您自己的应用程序,然后您可以使用 Try/Catch.由于该控件中的致命错误,它不会完全停止您的应用程序.但是使用该控件的那部分代码将不起作用.

When you are using some external controls/dlls in your application and you are not sure about its functioning and you do not want an error in that external control to stop your own application then you can use Try/ Catch. It will not entirely stop your application because of the fatal error in that control. But the part of your code using that control would not function.

这并不意味着您可以在自己的代码中使用 Try Catch 来避免致命错误,这可能会导致您的应用程序出现严重缺陷.

This does not mean that you can use Try Catch in your own code to avoid fatal errors this may cause serious flaw in your application.

Try/Catch 通常可用于调试应用程序,然后您可以删除 Try/Catch 块.

Try/Catch can generally be used to debug an application and after that you can remove the Try/Catch block.

这篇关于使用 try/catch 的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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