如何在不使用try catch的情况下处理异常? [英] How to handle exception without using try catch?

查看:228
本文介绍了如何在不使用try catch的情况下处理异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (SqlConnection con = new SqlConnection())
{
     try
     {
          con.Open();
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.Message);
     }
}

这很好。但是我想知道我们是否可以在不使用 try catch 之类的东西的情况下处理异常?还是使用 try catch 进行修改。

This works fine. But I want to know can we handle exception without using try catch like some thing if else? Or is it mendetory to use try catch.

推荐答案

没有除try catch以外的其他处理异常的机制。听起来您想要

There is no other mechanism to handle an exception other than try catch. It sounds like you want something like

if(connection.DidAnErrorOccur)

但这不存在。

这篇关于如何在不使用try catch的情况下处理异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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