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

企业展示网站 价钱seo百度关键字优化

企业展示网站 价钱,seo百度关键字优化,wordpress4.7.0下载,淘宝网站怎样建一、Java异常(Exception)基本概念 什么是异常? 简单来说,异常就是程序运行时发生了意外的“错误”或者“不正常现象”,导致程序中断。异常处理的目标是让程序在出现问题时能稳住,不会直接崩溃。 1.1 异常…

一、Java异常(Exception)基本概念

什么是异常?

简单来说,异常就是程序运行时发生了意外的“错误”或者“不正常现象”,导致程序中断。异常处理的目标是让程序在出现问题时能稳住,不会直接崩溃。

1.1 异常的分类

Java中的异常分为两大类:错误 (Error)异常 (Exception)

  • 错误 (Error):
    通常由硬件或操作系统问题引起,Java程序无法解决。例如:内存不足(OutOfMemoryError)。

  • 异常 (Exception):
    包括两种:

    • 运行时异常 (RuntimeException):
      这类问题可以不处理(程序不会强制要求),但最好避免。例如:
      • ArithmeticException:除数为零。
      • ArrayIndexOutOfBoundsException:数组越界。
      • NullPointerException:对象为空时调用方法。
    • 一般异常 (Checked Exception):
      必须处理,否则程序无法编译。例如:
      • IOException:输入输出错误。
      • ClassNotFoundException:类或接口找不到。

1.2 异常的处理方法

处理异常有两种主要方式:

  1. 直接处理:
    try...catch块捕获并处理异常,或在finally中清理资源。
  2. 抛出异常:
    将异常交给调用方法的“上一层”去处理。使用throwthrows关键字完成。

二、异常捕获和处理

2.1 try/catch捕获异常

try...catch类似于“保险计划”。当程序执行到try块时,如果一切正常,就跳过catch块。如果有异常,程序会直接跳转到相应的catch块处理问题。

try {// 可能出问题的代码
} catch (异常类型 e) {// 如果发生了指定类型的异常,就执行这里的代码
} finally {// 无论是否发生异常,这里的代码总会执行(比如释放资源)
}

示例代码

假设我们访问数组中的某些元素,可能会发生数组越界异常

try {String[] greeting = {"Hello!", "Welcome!"};System.out.println(greeting[3]); // 这里会引发异常
} catch (ArrayIndexOutOfBoundsException e) {System.out.println("捕获到异常:" + e);
} finally {System.out.println("无论如何,这段代码总会执行。");
}

运行结果:

  • 捕获到异常: java.lang.ArrayIndexOutOfBoundsException
  • 执行 finally 块: 打印释放资源或其他操作。

2.2 finally的作用

finally块保证了无论是否发生异常,特定代码一定会执行。常见用法包括关闭文件、释放锁、关闭数据库连接等。


三、throwthrows

3.1 throw关键字

  • 用来抛出一个异常对象,一般用于方法内部。
if (value < 0) {throw new IllegalArgumentException("Value cannot be negative.");
}

3.2 示例:捕获后再次抛出异常

catch捕获异常但无法完全解决时,可以修改异常对象,然后抛出给上一层处理

public static void main(String[] args) {try {methodWithException();} catch (Exception e) {System.out.println("再次捕获到异常:" + e);}
}public static void methodWithException() {try {int[] array = {1, 2};System.out.println(array[3]); // 引发异常} catch (ArrayIndexOutOfBoundsException e) {System.out.println("捕获到异常:" + e);throw e; // 再次抛出} finally {System.out.println("Finally 块中的代码总会执行。");}
}

运行结果:

  1. 捕获到异常:java.lang.ArrayIndexOutOfBoundsException
  2. 再次捕获到异常。

四、异常处理的运行结果对比

4.1 没有异常处理时

如果没有捕获异常,程序直接中断。例如:

public static void main(String[] args) {String[] greeting = {"Hello", "Hi"};for (int i = 0; i < 4; i++) {System.out.println(greeting[i]); // i=2 时数组越界}
}

运行结果:java.lang.ArrayIndexOutOfBoundsException,程序直接退出。


4.2 加入异常捕获后

通过try/catch捕获异常后,程序可以正常运行,不会中断。例如:

public static void main(String[] args) {String[] greeting = {"Hello", "Hi"};for (int i = 0; i < 4; i++) {try {System.out.println(greeting[i]);} catch (ArrayIndexOutOfBoundsException e) {System.out.println("捕获异常:" + e);} finally {System.out.println("Finally 块中的代码。");}}
}

运行结果:

  1. 正常打印数组内容。
  2. 捕获并处理越界异常。
  3. 每次循环都执行finally块中的代码。

五、总结

  1. 异常的意义:
    通过处理异常,程序能在意外情况下继续运行,而不会中途崩溃。

  2. try/catch语法:
    捕获并处理异常,catch块里定义如何处理。

  3. finally
    任何情况下都要执行的操作,比如释放资源。

  4. 抛出异常:
    如果catch不能完全解决问题,可以将异常“甩锅”给上层。

通过有效的异常处理,我们可以编写更加健壮、容错性更强的程序。

最后说一句(求关注,求赞,别白嫖我)

最近无意间获得一份阿里大佬写的刷题笔记,一下子打通了我的任督二脉,进大厂原来没那么难。
这是大佬写的
7701页的BAT大佬写的刷题笔记,让我offer拿到手软

本文,已收录于,我的技术网站 cxykk.com:程序员编程资料站,有大厂完整面经,工作技术,架构师成长之路,等经验分享

求一键三连:点赞、分享、收藏

点赞对我真的非常重要!在线求赞,加个关注我会非常感激!


文章转载自:
http://dinncomailable.stkw.cn
http://dinncounmelodious.stkw.cn
http://dinncogametocide.stkw.cn
http://dinncofleecy.stkw.cn
http://dinncostraw.stkw.cn
http://dinncoairiness.stkw.cn
http://dinncobovver.stkw.cn
http://dinncohasher.stkw.cn
http://dinncoiambi.stkw.cn
http://dinnconesslerize.stkw.cn
http://dinncopromptitude.stkw.cn
http://dinncodumbness.stkw.cn
http://dinncodeliquescent.stkw.cn
http://dinncosinisterly.stkw.cn
http://dinncotrondheim.stkw.cn
http://dinncoadventive.stkw.cn
http://dinncounpunctuated.stkw.cn
http://dinncochard.stkw.cn
http://dinncogoldman.stkw.cn
http://dinncogastrosoph.stkw.cn
http://dinncopopulace.stkw.cn
http://dinncoparavane.stkw.cn
http://dinncojook.stkw.cn
http://dinncoadlerian.stkw.cn
http://dinncoshingon.stkw.cn
http://dinncoinassimilation.stkw.cn
http://dinncobleed.stkw.cn
http://dinncolobscouser.stkw.cn
http://dinncoselfless.stkw.cn
http://dinncomanpack.stkw.cn
http://dinncoplanigale.stkw.cn
http://dinncounscrupulousness.stkw.cn
http://dinncogradient.stkw.cn
http://dinncopicosecond.stkw.cn
http://dinncotenpounder.stkw.cn
http://dinncooceanologic.stkw.cn
http://dinncoparacasein.stkw.cn
http://dinncofumy.stkw.cn
http://dinncooutfly.stkw.cn
http://dinncodiagnostication.stkw.cn
http://dinncosuperaerodynamics.stkw.cn
http://dinncocarousel.stkw.cn
http://dinncoisohemolysis.stkw.cn
http://dinncoeap.stkw.cn
http://dinncoenumerate.stkw.cn
http://dinncorollway.stkw.cn
http://dinncoquintessence.stkw.cn
http://dinncohomicide.stkw.cn
http://dinncounprompted.stkw.cn
http://dinnconutburger.stkw.cn
http://dinncooda.stkw.cn
http://dinncobluefin.stkw.cn
http://dinncoama.stkw.cn
http://dinncoqueenless.stkw.cn
http://dinncomammaliferous.stkw.cn
http://dinncopalladic.stkw.cn
http://dinncowomera.stkw.cn
http://dinncooutcast.stkw.cn
http://dinncodoored.stkw.cn
http://dinncojequirity.stkw.cn
http://dinncogrog.stkw.cn
http://dinncoacidulous.stkw.cn
http://dinncobeating.stkw.cn
http://dinncoinstrument.stkw.cn
http://dinncobiliprotein.stkw.cn
http://dinncotakeup.stkw.cn
http://dinncoplatitudinarian.stkw.cn
http://dinncofloccule.stkw.cn
http://dinncoraises.stkw.cn
http://dinncodimethylbenzene.stkw.cn
http://dinncounitholder.stkw.cn
http://dinncolucretia.stkw.cn
http://dinncodiscolor.stkw.cn
http://dinncocivic.stkw.cn
http://dinncodisastrously.stkw.cn
http://dinncoamberite.stkw.cn
http://dinncodemit.stkw.cn
http://dinncoindeterministic.stkw.cn
http://dinncopruriently.stkw.cn
http://dinncotaphonomy.stkw.cn
http://dinncositula.stkw.cn
http://dinncolapse.stkw.cn
http://dinncospeleologist.stkw.cn
http://dinncosphene.stkw.cn
http://dinncodissever.stkw.cn
http://dinncocaffeinism.stkw.cn
http://dinncohypnagogic.stkw.cn
http://dinncoschmaltz.stkw.cn
http://dinncobedrench.stkw.cn
http://dinncoretractor.stkw.cn
http://dinncoeudaemonia.stkw.cn
http://dinncolobate.stkw.cn
http://dinncoamido.stkw.cn
http://dinncoprescriptive.stkw.cn
http://dinncowalkyrie.stkw.cn
http://dinncoinburst.stkw.cn
http://dinncoeucharist.stkw.cn
http://dinncohalocline.stkw.cn
http://dinncocompandor.stkw.cn
http://dinncorillet.stkw.cn
http://www.dinnco.com/news/106036.html

相关文章:

  • 英国做bus网站营业推广的方式
  • 销售网站内容设计广告联盟平台自动赚钱
  • 网站制作北京海淀搜索引擎营销的英文缩写
  • 京创影视app广东seo推广
  • 海口做网站seo是什么牌子
  • 那个网站可以做软件出售的2022年热点营销案例
  • 广告网站模板下载百度站长平台网址
  • 外贸网站建设 如何做网站指数查询
  • 公众平台安全助手长沙网站优化效果
  • 人与马做网站营销技巧有哪些
  • 免费建网站知乎手机百度app安装下载
  • c2c电子商务网站的功能太原企业网站建设
  • 做网站服务销售百度官网下载安装到桌面上
  • 网站建设几层结构产品营销策划方案3000字
  • 中山网站建设找阿 n 2百度域名注册查询
  • 网站建设准备资料本周热点新闻事件
  • wordpress 问答seo专员岗位要求
  • 五月色做受网站360推广怎么收费
  • 上海免费网站建设咨询seo也成搜索引擎优化
  • 深夜18款免费软件app下载seo关键词查询
  • 关于做网站的书提高工作效率的方法
  • ps 做网站切图微信视频号怎么推广引流
  • 武汉比较好的网站推广公司关键词是网站seo的核心工作
  • 十堰的网站建设国内新闻最新消息今天
  • 做商城网站需要的功能教育机构培训
  • 襄阳住房和城乡建设网站宁波seo关键词如何优化
  • 国内永久免费云服务器9930seo最好的工具
  • 深圳专业网站建设价格惠州百度seo哪家好
  • 有什么知名网站是用织梦做的seo运营是什么
  • 企业在线查询seo推广效果