异常--throw
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace @throw
{
class test
{
public int Myint(string a, string b)
{
int intn1;
int intn2;
int num;
intn1 = int.Parse(a);
intn2 = int.Parse(b);
if(intn2 == 0)
{
throw new DivideByZeroException();
return 0;
}
else
{
num = intn1 / intn2;
return num;
}
}
} class Program
{
static void Main(string[] args)
{
while(true)
{
Console.WriteLine("请输入分子:");
string str1 = Console.ReadLine();
Console.WriteLine("请输入分母:");
string str2 = Console.ReadLine();
test tt = new test();
Console.WriteLine(tt.Myint(str1,str2));
}
}
}
}
throw在特定情况下主动抛出异常
(1)ArithmeticException
(2)ArrayTypeMismatchException
(3)DivideByZeroException
(4)IndexOutOfRangeException
(5)InvalidCastException
(6)NullReferenceException
(7)OutOfMemoryException
(8)OverflowException
(9)StackOverflowException
(10)TypeInitializationException
异常--throw的更多相关文章
- 异常-throw的概述以及和throws的区别
package cn.itcast_06; /* * throw:如果出现了异常情况,我们可以把该异常抛出,这个时候的抛出的应该是异常的对象. * * throws和throw的区别(面试题) thr ...
- Java中处理异常throw和throws
1.首先我们来了解什么是异常呢? 异常阻止当前方法或作用域继续执行的问题. 2.处理异常 说到处理异常,我们当然会想到 try catch finally 在java中我们会对异常的处理有更高的认识 ...
- JAVA 异常 throw 与 throws
最近一直throw和throw new …… 获取头部罢工,要彻底生气清楚这件事,他对这个思想精华收集了很多网友.这里摘录. throws全部异常信息throw则是指抛出的一个详细的异常类型.通常在一 ...
- java为什么有些异常throw出去需要在函数头用throws声明,一些就不用。
Excepiton分两类:checked exception.runtime exception:直接继承自Exception就是checked exception,继承自RuntimeExcepti ...
- JS Error 内置异常类型 处理异常 Throw语句
Exceptional Exception Handling in JavaScript MDN资料 Anything that can go wrong, will go wrong. ...
- 【Java】异常 —— throw, throws, try catch 相关内容
嗯……面试考到了这个,又是一个如无意外 那么接下来就总结吧 一.什么是异常 程序运行过程中发生的异常事件. RuntimeException通常是因为编程员因为疏忽没有检查而引起的错误. 二.Exce ...
- 为什么有些异常throw出去需要在函数头用throws声明,一些就不用
throw new IllegalStateException(".");不用在函数头声明throws IllegalStateExceptionthrow new IOExcep ...
- JAVA笔记9__异常/throw关键字/自定义异常/受检与非受检异常、assert关键字/StringBuffer、StringBuilder/代码国际化、动态文本
/** * 异常:在程序中导致程序中断运行的一些指令 * 1.受检异常:编译期 * 2.非受检异常:运行期 * 异常处理过程分析: * 1.一旦产生异常,系统会自动产生一个异常类的实例化对象 * 2. ...
- 抛异常 throw的注意事项
子类覆盖父类只能抛出父类的异常或者子类或者子集注意:如果父类的方法没有抛异常,那么子类覆盖时绝对不能抛. 子类继承父类时,方法抛异常,要么抛父类,要么抛父类下的子类,不能抛父类平级或以上的异常 原因是 ...
- java 异常 throw
throw UnsupportedOperationException(); //没有支持的操作NoSuchElementException(); //没有这样的元素
随机推荐
- HyperLedger Fabric 1.4 智能合约 Helloworld运行(9)
9.1 Helloworld案例简介 通过执行官方End-2-End案例,初始了解Fabric网络的运行流程及yaml配置,官方End-2-End案例把执行过程集成,通过一条命令即可完成全 ...
- Touch table
On this page I present the results of my touch action research. I concentrated on the few basic acti ...
- 【BZOJ2286】消耗战(虚树,动态规划)
[BZOJ2286]消耗战(虚树,动态规划) 题面 BZOJ Description 在一场战争中,战场由n个岛屿和n-1个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总 ...
- Java Dictionary Example
Dictionary class is the abstract class which is parent of any class which uses the key and value pai ...
- hdu1045Fire Net(经典dfs)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Qt-QSplashScreen-程序启动动画
多数大型应用程序启动时可会在程序完全启动前显示一个启动画面,在程序完全启动后消失,程序启动画面可以显示相关产品的一些信息,使用户在等待程序启动时同时了解产品的相关功能,这也是一种宣传方式. 首先运行界 ...
- [CodeForce431C]k-tree
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired ...
- 打包一个Docker镜像,让你的好友加载开启一个容器,并且每隔一秒输出hello,world到指定的文件中
一.两个脚本代码 Dockerfile FROM bash COPY . /usr/herui/ WORKDIR /usr/herui/ CMD [ "sh", "hel ...
- jmeter链接数据库问题汇总
1.最新驱动下载: 驱动版本与mysql服务不兼容也是会报错的 下载地址:https://dev.mysql.com/downloads/connector/j/ 打开页面一直拉到页面底部,此处选择P ...
- jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别
$().ready().$(handler).$(document).ready(handler)均不是原生JS中的,都是jQuery中封装的方法.这些事件在当页面的dom节点加载完毕后就执行,无需等 ...