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的更多相关文章

  1. 异常-throw的概述以及和throws的区别

    package cn.itcast_06; /* * throw:如果出现了异常情况,我们可以把该异常抛出,这个时候的抛出的应该是异常的对象. * * throws和throw的区别(面试题) thr ...

  2. Java中处理异常throw和throws

    1.首先我们来了解什么是异常呢? 异常阻止当前方法或作用域继续执行的问题. 2.处理异常 说到处理异常,我们当然会想到 try catch finally 在java中我们会对异常的处理有更高的认识 ...

  3. JAVA 异常 throw 与 throws

    最近一直throw和throw new …… 获取头部罢工,要彻底生气清楚这件事,他对这个思想精华收集了很多网友.这里摘录. throws全部异常信息throw则是指抛出的一个详细的异常类型.通常在一 ...

  4. java为什么有些异常throw出去需要在函数头用throws声明,一些就不用。

    Excepiton分两类:checked exception.runtime exception:直接继承自Exception就是checked exception,继承自RuntimeExcepti ...

  5. JS Error 内置异常类型 处理异常 Throw语句

    Exceptional Exception Handling in JavaScript       MDN资料 Anything that can go wrong, will go wrong. ...

  6. 【Java】异常 —— throw, throws, try catch 相关内容

    嗯……面试考到了这个,又是一个如无意外 那么接下来就总结吧 一.什么是异常 程序运行过程中发生的异常事件. RuntimeException通常是因为编程员因为疏忽没有检查而引起的错误. 二.Exce ...

  7. 为什么有些异常throw出去需要在函数头用throws声明,一些就不用

    throw new IllegalStateException(".");不用在函数头声明throws IllegalStateExceptionthrow new IOExcep ...

  8. JAVA笔记9__异常/throw关键字/自定义异常/受检与非受检异常、assert关键字/StringBuffer、StringBuilder/代码国际化、动态文本

    /** * 异常:在程序中导致程序中断运行的一些指令 * 1.受检异常:编译期 * 2.非受检异常:运行期 * 异常处理过程分析: * 1.一旦产生异常,系统会自动产生一个异常类的实例化对象 * 2. ...

  9. 抛异常 throw的注意事项

    子类覆盖父类只能抛出父类的异常或者子类或者子集注意:如果父类的方法没有抛异常,那么子类覆盖时绝对不能抛. 子类继承父类时,方法抛异常,要么抛父类,要么抛父类下的子类,不能抛父类平级或以上的异常 原因是 ...

  10. java 异常 throw

    throw UnsupportedOperationException(); //没有支持的操作NoSuchElementException(); //没有这样的元素

随机推荐

  1. ruby中的extend 和 include

    include include是把module中定义的instance_method给mixin,然后当做类的实例方法使用(是因为module本身不能使用module的实例方法),给类进行实例化一个对 ...

  2. 15-oauth2+oidc实现Server部分

    1-我们使用之前项目的mvcCookieAuthSampe2进行改造 1.1  增加IdentityServer4 2-增加Config.cs文件,对IdentityServer提供相关的配置数据 u ...

  3. javascript sorting/ v8 sorting

    https://github.com/mgechev/v8-sorting-test/tree/master/src/algorithms

  4. Alexander的Python机器学习 之目录分析。

    无聊,顺应一下潮流,学习一下python机器学习吧. 买了一本书,首先分析一下目录吧. 1.第一章是 Python机器学习的生态系统. 1.1.数据科学或机器学习的工作流程. 然后又分成6点进行详细说 ...

  5. SpringBoot-03:SpringBoot+Idea热部署

      ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 所谓热部署,就是在项目启动中,修改class类中做的修改操作,无需重新启动项目,就可以变更,在网页展示中有 ...

  6. STM32的System memory

    Main Flash memory 是STM32内置的Flash,一般我们使用JTAG或者SWD模式下载程序时,就是下载到这个里面,重启后也直接从这启动程序. System memory 从系统存储器 ...

  7. Fat Jar - Myeclipse插件安装使用方法- 完美解决

    Eclipse可以安装一个叫Fat Jar的插件,用这个插件打包非常方便,Fat Jar的功能非常强大. 工具/原料 Eclipse Kepler Fat Jar 方法/步骤 1 Fat Jar功能非 ...

  8. PHP程序员如何理解依赖注入容器(dependency injection container)

    背景知识 传统的思路是应用程序用到一个Foo类,就会创建Foo类并调用Foo类的方法,假如这个方法内需要一个Bar类,就会创建Bar类并调用Bar类的方法,而这个方法内需要一个Bim类,就会创建Bim ...

  9. c++ reference can not be reassigned

    #include <iostream> using namespace std; int main () { // declare simple variables int i; int ...

  10. python 终极篇 --- django 路由系统

                          URL配置                        基本格式: from django.conf.urls import url urlpattern ...