比如一个异常
public String test(String tt){
if(tt.equals("行"))
{
......
}else{
throw new Exception("出现异常");
//这里抛出的异常完全由自己控制,想显示什么就显示什么,能做到吗?
}
}
public String test(String tt){
if(tt.equals("行"))
{
......
}else{
throw new Exception("出现异常");
//这里抛出的异常完全由自己控制,想显示什么就显示什么,能做到吗?
}
}
这样的怎么去掉?
int temp = Integer.parseInt(ch);
}
catch (Exception ex) {
//这里写你的代码比方说,System.out.println(""+ch);
}
当转型时发生异常,则把ch打印出来。不会有
***.***.***(57****) ***.java之类的
比如说
public String test(String tt){
if(tt.equals("行"))
{
......
}else{
throw new Exception("出现异常");//这里中断了程序的运行,并抛出的异常完全由自己控制,想显示什么就显示什么,能做到吗?
}
}用throw new Exception可以中断程序的运行,但是所抛出的并不能完全由自己定义
我想做的是 中断了程序的运行,打印出原来设定好的值。
to yangFrame:
按你的意思可以这样:try{
if (tt.equals("asdf"))
{
out.print("asdf");
}else{
throw new Exception("出现错误!");
out.println("asdf");
out.println("<br>");
out.println("asdfdfdf");
}
}catch(Exception e)
{
out.println(e.getMessage());
}但是这样有个缺点,就是所有得程序都得被try catche包含着,我希望做的是不被包含着的,可以直接中断程序、打印出自己定义的结果的
但问题是最外层中,抓Exception之后,就可以显示try catch之后的东西了,我希望的不能显示try catch之后的东西
public void test(httpServletResponse response){
if(.....){
}else{
response.sendRedirect("your.jsp");//your.jsp想显示什么就写什么(因为是直接发送到另外一个页面的,所以直接退出了,嘿嘿)
}
}