就在catch块里啊,你只要有条错误信息就可以拉
System.out.Println("出错!");学习中,关注中!

解决方案 »

  1.   

    这样呀,我的意思是如这样的函数
    public void initData(String dataDriver) throws ClassNotFoundException{
    Class.forName(dataDriver);
    }
    没有try{..}catch(..){}这样的语句还有:有了 throws Exception 还能用TRY{}CATCH(){}语句吗??????
      

  2.   

    public String name_fun() throws Exception{
    ......
    }===>>public String name_fun(){
      try{
        ......
      }catch(Exception ex){
        ...;//异常处理
      }
    }
      

  3.   

    name_fun() 是一个方法,你可以在调用他的时候try
    try{
         //String dataDriver 
         String returnValue = name_fun(dataDriver) 
    }catche(ClassNotFoundException ex){
        ex.printStackTrace();
        //你自己的处理
    }
      

  4.   

    或者在内部先处理后再抛出异常给调用他的程序处理
    public String name_fun(String dataDriver ){
      try{
        Class.forName(dataDriver);
      }catch(ClassNotFoundException ex){
        ...;//异常处理
        throw ex;
      }
    }
      

  5.   

    有了 throws Exception 还能用TRY{}CATCH(){}语句吗??????答:可以!
      

  6.   

    还想麻烦一下各位老大:
    我在index.jsp中定义了:<%@ page isErrorPage="true" errorPage="error.jsp"%>
    并且error.jsp这样写:
    <%@ page isErrorPage="true" language="java" contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*" %>
    <%@ page errorPage="error.jsp" %>
    <%
    Exception ex;
    ex;
    if(ex.getMessage()!=null) out.print(ex.getMessage());
    %>
    结果报错
      

  7.   

    我想要的效果是这样的:
    错误码: 500 
    讯息: Unable to compile class for JSP An error occurred at line: 3 in the jsp file: /sam/test/manage/error.jsp Generated servlet error: [javac] Compiling 1 source file D:\Sun\AppServer\domains\jakarta-tomcat-4.1.30\work\Standalone\localhost\_\sam\test\manage\error_jsp.java:48: not a statement ex; ^ 1 error 
    异常: class org.apache.jasper.JasperException 
    这样是怎么做出来的呀????????????????急
      

  8.   

    给楼主一段书上的例子,建议多看看基础知识。下面的程序试图抛出一个它不捕捉的异常,因为这个程序没有指定一个throws子句来声明抛出异常,所以程序不能编译通过。
    【例6.4】无声明的抛出异常
    public class Exception6
    {
    static void throwOne()
    {
    System.out.println ("抛出内部异常。");
      throw new IllegalAccessException ("demo");
    }
    public static void main (String[] args)
    {
    throwOne();
    }
    }
    为了使这个程序编译成功,需要进行两处修改。首先,需要声明方法throwOne()抛出了IllegalAccessException异常。然后,必须在main()中定义try-catch语句来捕捉这个异常。修改的正确程序如下:
    【例6.5】声明抛出异常
    public class Exception7
    {
    static void throwOne() throws IllegalAccessException 
    {
    System.out.println ("抛出内部异常。");
      throw new IllegalAccessException ("demo");
    }
    public static void main (String[] args)
    {
    try{
    throwOne();
    }
    catch(IllegalAccessException e){
    System.out.println ("捕捉到异常为:"+e);
    }
    }
    }
    运行结果如下:
    抛出内部异常。
    捕捉到异常为:java.lang.IllegalAccessException: demo