异常类
Posted Kooing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常类相关的知识,希望对你有一定的参考价值。
int a=0,b=0,c=0; try{ a=Integer.parseInt("888"); b=Integer.parseInt("as888");//这个try在这中断 c=88; } catch(NumberFormatException e){ System.out.println("发生异常 "+e.getMessage()); } System.out.printf("%d %d %d",a,b,c); try{ throw new java.io.IOException("fuck"); } catch(java.io.IOException e){ System.out.println(e.getMessage()); }
import java.util.Scanner; public class test{ public static void main(String args[]){ Bank bank=new Bank(); try{ bank.income(111, 32); bank.income(23323,324); bank.income(2323, 34); bank.income(2, -34234); bank.income(23, 2); } catch(BankException a){ System.out.println(a.readMessage()); } } } class BankException extends Exception{ String message; public BankException(int a,int b){ message="出错了日你"; } String readMessage(){ return message; } } class Bank{ int money; void income(int a,int b)throws BankException{//在这里就要声明要产生的异常 if(a+b<0){ throw new BankException(a,b);//然后写出具体的异常操作 } money=a+b; System.out.println("input ..."+money); } }
断言
aasert
assert 表达式:一条string
int []a={1,-2,3,-4,3}; for(int i:a){ assert i>0:"不能小于0"; System.out.println(i); }
以上是关于异常类的主要内容,如果未能解决你的问题,请参考以下文章
mvn命令异常:An error has occurred in Javadoc report generation: Unable to find javadoc command异常已解决(代码片段
mvn命令异常:An error has occurred in Javadoc report generation: Unable to find javadoc command异常已解决(代码片段
springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found(代码片段