抛出异常java时停止执行其余代码

时间:2014-04-08 23:58:41

标签: java exception exception-handling

所以假设我有三个java类A,B和C(不是实际的java语法),请参阅下面的内容,我在class B中有一些代码,我在class C发生异常时不执行该代码行有没有办法管理这种情况?

A.java

class A{

     method a() {
       try{
         //calling method b
         B bObj= new B();
         bObj.b();
      }catch{

      }
     }


    public static void main(String arg[]){

          a();
     }


}

B.java

class B {

  method b()throws Exception {
    //calling method c
       C cObj = new C();
        cObj.c();
       /// here is some line of code
       // which i dont wana execute when exception occurred in method c
  }
}

C.java

class C {
metho c(){
       try {
          //database connection
          // executing query
       }catch{
            // closing connection
       }
} // end of method c

}

0 个答案:

没有答案