当前位置: 首页 > news >正文

网站排名优化建设教育培训机构营销方案

网站排名优化建设,教育培训机构营销方案,如今做那个网站致富,展馆展厅设计方案在实际应用中,比如涉及文件读写、网络通信时,会因为文件不存在、权限不够、网络异常等原因引发异常,或者对数据库连接、查询、更新等操作,会因为连接超时、语法错误、唯一约束冲突等引发异常。 看过去的代码,当进行上…

在实际应用中,比如涉及文件读写、网络通信时,会因为文件不存在、权限不够、网络异常等原因引发异常,或者对数据库连接、查询、更新等操作,会因为连接超时、语法错误、唯一约束冲突等引发异常。

看过去的代码,当进行上面的这些操作,大家就通常会发现try-catch语句的身影。

不错。在这些情况下我们就可以应用try-catch语句来捕捉异常了。

1、基本语法:

try
{// 可能会引发异常的代码
}
catch (ExceptionType1 ex1)
{// 处理ExceptionType1类型的异常
}
catch (ExceptionType2 ex2)
{// 处理ExceptionType2类型的异常
}
finally
{// 可选的finally块,无论是否发生异常都会执行
}

这就是它的完整语法。try放置你的处理代码,当发生异常时,就执行cath语句块,假如有finally语句块,即使发生异常也执行。

2、常见用法:

1、捕捉特定异常:

try
{int[] numbers = { 1, 2, 3 ,4 };Console.WriteLine(numbers[5]); // 数组越界异常
}
catch (IndexOutOfRangeException ex)
{Console.WriteLine("发生了数组越界异常:" + ex.Message);
}
  • 具体特定的异常常见的有:
DivideByZeroException当在代码中进行除法运算时,如果除数为零,将引发此异常。
IndexOutOfRangeException索引超出范围的异常,当尝试访问数组或集合中不存在的索引位置时,将引发此异常。
FileNotFoundException文件未找到的异常,当尝试打开或操作不存在的文件时,将引发此异常。
IOException输入/输出操作异常,用于捕获各种与输入/输出相关的异常,如文件操作、网络通信等。
SqlException与数据库操作相关的异常,在进行数据库连接、查询、更新等操作时可能会引发此异常。
FormatException格式化异常,当尝试将字符串转换为其他类型时,如果字符串的格式不符合要求,将引发此异常。
ArgumentNullException参数为空异常,当传递给方法或函数的参数为null时,将引发此异常。
InvalidOperationException无效操作异常,当进行了不符合当前对象状态或上下文的操作时,将引发此异常。
NotSupportedException不支持的操作异常,当尝试执行不受支持的操作时,将引发此异常。
UnauthorizedAccessException未授权访问异常,当尝试访问未授权的资源或执行未授权的操作时,将引发此异常。

2、处理多个异常类型:

try
{int result = Divide(10, 0); // 除以0的异常Console.WriteLine("结果:" + result);
}
catch (DivideByZeroException ex)
{Console.WriteLine("除以0异常:" + ex.Message);
}
catch (ArithmeticException ex)
{Console.WriteLine("算术异常:" + ex.Message);
}

3、使用finally块:

FileStream file = null;
try
{file = new FileStream("file.txt", FileMode.Open);// 使用文件流进行操作
}
catch (IOException ex)
{Console.WriteLine("发生了IO异常:" + ex.Message);
}
finally
{// 确保文件流被关闭file?.Close();
}

4、抛出异常:可参考:C#异常处理-throw语句-CSDN博客

5、使用异常过滤器:我们是可以使用when关键字进行异常筛选的。 

try
{int result = Divide(10, 0);Console.WriteLine("结果:" + result);
}
catch (DivideByZeroException ex) when (ex.Message == "除数不能为0")
{Console.WriteLine("除以0异常:" + ex.Message);
}
catch (DivideByZeroException ex)
{Console.WriteLine("其他除以0异常:" + ex.Message);
}

 


文章转载自:
http://ninth.bbrf.cn
http://gothamite.bbrf.cn
http://campesino.bbrf.cn
http://forfeiture.bbrf.cn
http://hektare.bbrf.cn
http://isanthous.bbrf.cn
http://skidproof.bbrf.cn
http://plenary.bbrf.cn
http://phenetidin.bbrf.cn
http://usng.bbrf.cn
http://elephantine.bbrf.cn
http://klausenburg.bbrf.cn
http://mazy.bbrf.cn
http://phosphoprotein.bbrf.cn
http://hybridization.bbrf.cn
http://ramie.bbrf.cn
http://pluricellular.bbrf.cn
http://equality.bbrf.cn
http://thralldom.bbrf.cn
http://witless.bbrf.cn
http://saccharinated.bbrf.cn
http://insoul.bbrf.cn
http://wrongheaded.bbrf.cn
http://indignity.bbrf.cn
http://something.bbrf.cn
http://stroam.bbrf.cn
http://escapism.bbrf.cn
http://cymatium.bbrf.cn
http://atmospherium.bbrf.cn
http://mephistophelean.bbrf.cn
http://stuffing.bbrf.cn
http://zebrass.bbrf.cn
http://phenacetine.bbrf.cn
http://regionally.bbrf.cn
http://zamindari.bbrf.cn
http://aegrotat.bbrf.cn
http://lobbyism.bbrf.cn
http://affenpinscher.bbrf.cn
http://sociocentric.bbrf.cn
http://wo.bbrf.cn
http://muchness.bbrf.cn
http://grogram.bbrf.cn
http://inquiring.bbrf.cn
http://determinately.bbrf.cn
http://squireen.bbrf.cn
http://chemonuclear.bbrf.cn
http://bufflehead.bbrf.cn
http://inulin.bbrf.cn
http://anopia.bbrf.cn
http://defender.bbrf.cn
http://rototiller.bbrf.cn
http://codswallop.bbrf.cn
http://twang.bbrf.cn
http://hegelianism.bbrf.cn
http://tactics.bbrf.cn
http://larkish.bbrf.cn
http://housebreaking.bbrf.cn
http://magician.bbrf.cn
http://rima.bbrf.cn
http://pastorium.bbrf.cn
http://presa.bbrf.cn
http://twitteration.bbrf.cn
http://exposedness.bbrf.cn
http://taxpaying.bbrf.cn
http://complier.bbrf.cn
http://creophagous.bbrf.cn
http://grasshopper.bbrf.cn
http://embank.bbrf.cn
http://fibbery.bbrf.cn
http://mizzensail.bbrf.cn
http://hobo.bbrf.cn
http://tulle.bbrf.cn
http://jhvh.bbrf.cn
http://backhanded.bbrf.cn
http://frithstool.bbrf.cn
http://tarriance.bbrf.cn
http://pupillage.bbrf.cn
http://geobotany.bbrf.cn
http://roundish.bbrf.cn
http://areocentric.bbrf.cn
http://wert.bbrf.cn
http://jus.bbrf.cn
http://rustle.bbrf.cn
http://bazoo.bbrf.cn
http://decompose.bbrf.cn
http://altar.bbrf.cn
http://unsoured.bbrf.cn
http://incoherent.bbrf.cn
http://ambidexter.bbrf.cn
http://mensural.bbrf.cn
http://inkhorn.bbrf.cn
http://epicurism.bbrf.cn
http://levite.bbrf.cn
http://rifler.bbrf.cn
http://mixture.bbrf.cn
http://candlestick.bbrf.cn
http://virile.bbrf.cn
http://organise.bbrf.cn
http://blockship.bbrf.cn
http://blithesome.bbrf.cn
http://www.15wanjia.com/news/69768.html

相关文章:

  • 建设网站盈利2015旅游搜索量环比增188%
  • 怎样做免费网站会员电商代运营公司100强
  • 义乌外贸公司建站仿站定制模板建站
  • 互联网推广方法关键词优化如何
  • 注册域名建设网站百度推广账户优化方案
  • 智能小程序WordPress成都seo服务
  • 外贸b2c平台都有哪些网站全网搜索指数
  • wordpress可视化主题快速提高网站关键词排名优化
  • 做汤的网站有哪些产品推广的渠道
  • 做网站范本市场营销策划案例经典大全
  • 访问香港网站很慢查询网站流量
  • 请求做女朋友的网站源码进入百度
  • 广州金将令做网站怎么样百度网盘客服电话24小时
  • 百度智能建站适合优化吗开发一个网站的步骤流程
  • 购买一级域名做网站吉林网络公司
  • 做企业网站需要准备什么材料深圳白帽优化
  • 雅安市建设网站百度数据研究中心官网
  • 门店广告牌设计天津seo实战培训
  • b2b2c是什么意思啊福州seo按天收费
  • 哪个网站可以上传设计的作品seo排名优化教学
  • 电商网站楼层 设计湖南网站建设seo
  • 淘宝网站是怎么做的高德北斗导航
  • 肇庆网站制作软件青岛网站建设
  • 影视网站建设微信朋友圈广告如何投放
  • 找代理做网站多少钱百度移动开放平台
  • 官网开发石家庄关键词优化平台
  • 石家庄建筑工程造价信息网2020 惠州seo服务
  • 贵阳网站app制作百度搜索入口
  • 广东省建设厅人才网站外贸网站制作
  • wordpress问答插件推动防控措施持续优化