---
title: "异常处理类"
author: "tree3170"
date: "2012-06-19T09:56:30Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-06-19T09:56:30Z"
id: 1563644
url: "https://tree3170.iteye.com/blog/1563644"
---

```
class MyException1 extends Exception
 {
    int num;
    MyException1(int a)
    {
        num = a;
    }
    public String toString()
    {
        return num+"<10! 值必须大于10";
    }
}

class MyException2 extends Exception
{
    int num;
    MyException2(int a)
    {
        num = a;
    }
    public String toString()
    {
        return num+">100!/r/n值必须小于100";
    }
}

class MyExceptionTest
{
    static void makeException(int a) throws MyException1,MyException2
    {
        if(a<10)
            throw new MyException1(a);
        if(a>100)
            throw new MyException2(a);
        System.out.println("No Exception");
    }
    public static void main(String[] args)
    {
        int a;
        try
        {
            a = Integer.parseInt(args[0]);
            makeException(a);
            System.out.println("a="+a);
        }
        catch (MyException1 e)
        {
            System.out.println(""+e);
        }
        catch(MyException2 e)
        {
            System.out.println(""+e);
        }
    }
} 
```