首页 > 其他分享 >动手动脑

动手动脑

时间:2023-10-20 21:00:45浏览次数:25  
标签:Level 动脑 System try 动手 catch println out

一、

public class CatchWho {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}

throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}

 二、

public class CatchWho2 {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}

 三、

public class EmbededFinally {


public static void main(String args[]) {

int result;

try {

System.out.println("in Level 1");


try {

System.out.println("in Level 2");
// result=100/0; //Level 2

try {

System.out.println("in Level 3");

result=100/0; //Level 3

}

catch (Exception e) {

System.out.println("Level 3:" + e.getClass().toString());

}


finally {

System.out.println("In Level 3 finally");

}


// result=100/0; //Level 2


}

catch (Exception e) {

System.out.println("Level 2:" + e.getClass().toString());

}
finally {

System.out.println("In Level 2 finally");

}

// result = 100 / 0; //level 1

}

catch (Exception e) {

System.out.println("Level 1:" + e.getClass().toString());

}

finally {

. System.out.println("In Level 1 finally");

}

}

}

 

 Java通过使用try…catch…finally语句来捕获一个或多个异常,catch语句可以有一个或多个,而且至少要一个catch语句或finally。如果某处发生异常,则try语句中此处之后的代码都不会被执行。

标签:Level,动脑,System,try,动手,catch,println,out
From: https://www.cnblogs.com/zh-ang-zhang/p/17777986.html

相关文章

  • 动手动脑
    动手动脑:运行 TestInherits.java 可以得到结论:通过super调用基类构造方法,必须是子类构造方法中的第一个语句,调用顺序是由父类开始运行ParentChildTest 可以得出结论:当方法同名时,子类调用子类的方法,父类调用父类的方法,当父类和子类有同名变量且父类引用指向子类对象时......
  • 《动手学深度学习 Pytorch版》 9.8 束搜索
    本节将介绍几大:贪心搜索(greedysearch)策略穷举搜索(exhaustivesearch)束搜索(beamsearch)9.8.1贪心搜索贪心搜索已用于上一节的序列预测。对于输出序列的每一时间步\(t'\),都从\(\boldsymbol{Y}\)中找到具有最高条件概率的词元,即:\[y_{t'}=\mathop{\arg\max}\limits......
  • 《动手学深度学习 Pytorch版》 9.6 编码器-解码器架构
    为了处理这种长度可变的输入和输出,可以设计一个包含两个主要组件的编码器-解码器(encoder-decoder)架构:编码器(encoder):它接受一个长度可变的序列作为输入,并将其转换为具有固定形状的编码状态。解码器(decoder):它将固定形状的编码状态映射到长度可变的序列。9.6.1编码器编......
  • 《动手学深度学习 Pytorch版》 9.7 序列到序列学习(seq2seq)
    循环神经网络编码器使用长度可变的序列作为输入,将其编码到循环神经网络编码器固定形状的隐状态中。为了连续生成输出序列的词元,独立的循环神经网络解码器是基于输入序列的编码信息和输出序列已经看见的或者生成的词元来预测下一个词元。要点:“<eos>”表示序列结束词元,一旦输......
  • java课后动手动脑
    动手动脑Ⅰpackageorg.example;importjava.util.Scanner;importjavax.swing.*;publicclassMain{publicstaticvoidmain(Stringargs[]){inti=1,j=0,k;k=i/j;try{k=i/j;//Causesdivision-......
  • 2023/10/19 动手动脑
    首先,一个程序如果碰到了异常不处理,程序就会立即停止,而异常处理就是在异常发生的情况下启动类似于备用方案使程序继续运行Java中的异常捕获结构由try,catch,finally三部分构成,其中,try和catch是必须同时存在的。try中的代码就是可能存在异常的代码,catch中的代码就是try中有异常时的......
  • 动手动脑
    1.2.因为IEEE754标准规定:ANaNvalueisusedtorepresenttheresultofcertaininvalidoperationssuchasdividingzerobyzero. forexample, 1.0/0.0 hasthevaluepositiveinfinity,whilethevalueof 1.0/-0.0 isnegativeinfinity.意思就是NaN=0.0/......
  • 《动手学深度学习 Pytorch版》 9.5 机器翻译与数据集
    机器翻译(machinetranslation)指的是将序列从一种语言自动翻译成另一种语言,基于神经网络的方法通常被称为神经机器翻译(neuralmachinetranslation)。importosimporttorchfromd2limporttorchasd2l9.5.1下载和预处理数据集“Tab-delimitedBilingualSentencePairs”......
  • 《动手学深度学习 Pytorch版》 9.4 双向循环神经网络
    之前的序列学习中假设的目标是在给定观测的情况下对下一个输出进行建模,然而也存在需要后文预测前文的情况。9.4.1隐马尔可夫模型中的动态规划数学推导太复杂了,略。9.4.2双向模型双向循环神经网络(bidirectionalRNNs)添加了反向传递信息的隐藏层,以便更灵活地处理此类信息。9......
  • 《动手学深度学习 Pytorch版》 9.2 长短期记忆网络(LSTM)
    解决隐变量模型长期信息保存和短期输入缺失问题的最早方法之一是长短期存储器(longshort-termmemory,LSTM)。它与门控循环单元有许多一样的属性。长短期记忆网络的设计比门控循环单元稍微复杂一些,却比门控循环单元早诞生了近20年。9.2.1门控记忆元为了记录附加的信息,长短期记......