[ create a new paste ] login | about

Link: http://codepad.org/vKsPBy1e    [ raw code | output | fork ]

C++, pasted on Jun 19:
class testdata 
{
  void test1() {
    try {
      //何かエラー出そうな処理
    } catch (NullPointerException e) {
    
    } catch (OutoOfMemoryError e ) {
    
    }
  }
  
  void test2() {
   try {
      //何かエラー出そうな処理
    } catch (NullPointerException e) {
    
    } catch (OutoOfMemoryError e ) {
    
    }
  }
}

//↑のソースだと、両方共にぬるぽとか書かないといけないかつ
//増えてくるとそれだけ行が増える
//Javaが6で開発のため | 使えない
//↓のようにまとめたい

class testdata 
{
  void test1() {
    try {
      //何かエラー出そうな処理
    } catch (??? e) {
      //errorException呼び出し
    }
  }
  
  void test2() {
   try {
      //何かエラー出そうな処理
   } catch (??? e) {
      //errorException呼び出し
   } 
  }

  void errorException(??? e) {
    if(e == NullPointerException) 
    //↑if文でも何でもいいので対応するエラーを判定
    //複数記載
  }

}


Output:
1
2
3
t.cpp: In member function 'void testdata::test1()':
Line 6: error: expected type-specifier before 'NullPointerException'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: