1

この種の質問が以前にもあったことは知っており、それらを投げに行ったことがありますが、必要な最後の部分を取得できませんでした。

私の例外クラス

public class ProException extends Exception {
/**
 * 
 */
private static final long serialVersionUID = 1L;

public ProException(String message) {
    super(message);
  }
}

My ActivityClass (Android の ListView 用カスタム アダプター)

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    try {
        if (convertView == null) {
            vi = inflater.inflate(R.layout.pause_client_trigger_request_select_sku_list_row, null);
            tvItemName = (TextView) vi.findViewById(R.id.list_row_ItemName);                
        } else {
            tvItemName = (TextView) vi.findViewById(R.id.list_row_ItemName);
        }

        hmap = new HashMap<String, String>();
        hmap = data.get(position);
        tvItemName.setText(hmap.get(KEY_ItemName));

    } catch (ProException ex) {
        Log.i(Tag, ex.getMessage());
    }

    return vi;
}

今、私が欲しいのは。

このtry catch任意の例外で発生する例外がある場合。それは私のによってキャプチャされる必要がありますcustom class (ProException)。しかし、それは許されません。どんな助けでも

Java Eclipse エディターのメッセージ Unreachable catch block for ProException. This exception is never thrown from the try statement body

4

4 に答える 4

1

これらのビューはすべて、カスタム例外クラスを認識していません。カスタム例外をスローする独自のクラスを拡張/作成するか、ブロックView内で手動で例外をスローする必要があります。try

throw new ProException();

于 2013-06-03T10:22:56.650 に答える
0

ProException はカスタム例外です。コードブロックが例外をスローすると、カスタム例外を作成すると階層になるため、キャッチできません

Exception->>ProException 

Exceptionコード ブロックが例外をスローした場合、 の代わりに のcatch ブロックを見つけようとしますProException。または簡単に言えばIt will try to find out type of exception

したがって、Exception代わりにキャッチする必要がありますProException

カスタム例外は、どこかにスローするたびに役立ちます。

于 2013-06-03T11:25:22.787 に答える