可以写入中文异常信息来覆盖原信息啊。举个例子吧,但不知道是不是你想要的。- class MyException extends Exception
- {
- MyException(String msg) //这里覆盖原信息
- {
- super(msg);
- }
- }
- class Demo
- {
- int div(int a,int b)throws MyException
- {
- if(b==0)
- throw new MyException("出现了除数是零的情况 / by zero"); //传入你想要的中文信息
- return a/b;
- }
- }
- class ExceptionDemo
- {
- public static void main(String[] args)
- {
- Demo d = new Demo();
- try
- {
- int x = d.div(3,0);
- }
- catch (MyException e)
- {
- System.out.println(e.toString());
- }
- }
- }
复制代码 |