Catch块异常处理中的异常处理

Catch块异常处理中的异常处理

本文介绍了Try-Catch块异常处理中的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我知道,我们可以使用try-catch块来处理异常。但我对Try-Catch的使用有一些疑问。 有什么区别I know, we can use try-catch block to handle exceptions. But I have some doubts in the usage of Try-Catch.What is the difference betweentry{ //Some code}catch{} 和andtry{ //Some code}catch(Exception){} 和andtry{ //Some code}catch(Exception oops){} 在我的计划中,我需要抓住所有e xceptions,我不想记录它们。从上面提到的应该使用的Try-Catch块?In my program, I need to catch all exceptions and I don''t want to log them. From the above mentioned Try-Catch blocks, which should be used?推荐答案try{ // some code}catch (Exception ex){ Console.WriteLine(ex.Message); // writes the error message to the console} b $ b Kaizen202写道:Kaizen202 wrote:在我的程序中,我需要捕获所有异常,我不想记录它们。从上面提到的应该使用的Try-Catch块?In my program, I need to catch all exceptions and I don''t want to log them. From the above mentioned Try-Catch blocks, which should be used? 如果你不需要指定一个异常类型,如果你不想记录它们,然后使用If you don''t need to specify a exception type, and if you don''t want to log them, then usetry{ // some code}catch{} 如果您需要指定例外类型,但如果您不想记录它们,然后使用And if you need to specify an exception type, but if you don''t want to log them, then usetry{ // some code}catch (OutOfMemoryException) // change OutOfMemoryException into the type of the exception which you need to specify{} 但如果你需要记录它们,那么使用But if you need to log them, then usecatch (Exception ex) // change Exception into the type of the exception which you want to log 希望这会有所帮助。Hope this helps.try{}catch (AccessViolationException oops){}catch{} 意味着您将以特定方式处理AccessViolationException类型的错误,而您将以相同的方式处理所有其他类型的错误。which means that you will deal in a specific way for errors of type AccessViolationException while you will deal in the same way with all other types of errors. 这篇关于Try-Catch块异常处理中的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 10:39