KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > Catch1


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on 2004-11-13
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15
16 /**
17  * Catch1 implements Catch and recovers the exception only when the exception is the same object that it expects.
18  * @author Ben Yu
19  *
20  * 2004-11-13
21  */

22 public final class Catch1<T> implements Catch<T>, java.io.Serializable JavaDoc {
23
24   /**
25    * if e is the same as the target object that this Catch object is expecting,
26    * it recovers the parser and make v the current return value.
27    * @see jfun.parsec.Catch#catchException(java.lang.Object, java.lang.Object)
28    */

29   public Parser<T> catchException(Object JavaDoc v, Object JavaDoc e) {
30     if(e==target) return Parsers.retn(target);
31     else return Parsers.raise("uncaught", e);
32   }
33   private final T target;
34   
35
36   /**
37    * Create a Catch1 object.
38    * @param target the expected target exception object.
39    */

40   public Catch1(final T target) {
41     this.target = target;
42   }
43 }
44
Popular Tags