KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > jcd > cls > attribute > Exception_info


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: Exception_info.java,v 1.1.1.1 2004/05/09 16:57:48 vlad_r Exp $
8  */

9 package com.vladium.jcd.cls.attribute;
10
11 import java.io.IOException JavaDoc;
12
13 import com.vladium.jcd.compiler.IClassFormatOutput;
14 import com.vladium.jcd.lib.UDataInputStream;
15 import com.vladium.jcd.lib.UDataOutputStream;
16
17 // ----------------------------------------------------------------------------
18
/**
19  * An Exception_info is an entry layout format for {@link ExceptionHandlerTable}. Each
20  * entry contains the following items:
21  * <PRE>
22  * start_pc, end_pc
23  * </PRE>
24  * The values of the two items start_pc and end_pc indicate the ranges in the code
25  * array at which the exception handler is active. The value of start_pc must be
26  * a valid index into the code array of the opcode of an instruction. The value of
27  * end_pc either must be a valid index into the code array of the opcode of an
28  * instruction, or must be equal to code_length , the length of the code array.
29  * The value of start_pc must be less than the value of end_pc.<P>
30  *
31  * The start_pc is inclusive and end_pc is exclusive; that is, the exception handler
32  * must be active while the program counter is within the interval [start_pc, end_pc).
33  * <PRE>
34  * handler_pc
35  * </PRE>
36  * The value of the handler_pc item indicates the start of the exception handler.
37  * The value of the item must be a valid index into the code array, must be the index
38  * of the opcode of an instruction, and must be less than the value of the code_length
39  * item.
40  * <PRE>
41  * catch_type
42  * </PRE>
43  * If the value of the catch_type item is nonzero, it must be a valid index into the
44  * constant_pool table. The constant_pool entry at that index must be a
45  * {@link com.vladium.jcd.cls.constant.CONSTANT_Class_info} structure representing
46  * a class of exceptions that this exception handler is designated to catch.
47  * This class must be the class Throwable or one of its subclasses. The exception
48  * handler will be called only if the thrown exception is an instance of the given
49  * class or one of its subclasses.<P>
50  *
51  * If the value of the catch_type item is zero, this exception handler is called for
52  * all exceptions. This is used to implement finally.
53  *
54  * @author (C) 2001, Vlad Roubtsov
55  */

56 public
57 final class Exception_info implements Cloneable JavaDoc, IClassFormatOutput
58 {
59     // public: ................................................................
60

61     
62     public int m_start_pc, m_end_pc, m_handler_pc, m_catch_type;
63     
64     
65     public Exception_info (final int start_pc, final int end_pc,
66                            final int handler_pc, final int catch_type)
67     {
68         m_start_pc = start_pc;
69         m_end_pc = end_pc;
70         m_handler_pc = handler_pc;
71         m_catch_type = catch_type;
72     }
73     
74     
75     public String JavaDoc toString ()
76     {
77         return "exception_info: [start_pc/end_pc = " + m_start_pc + '/' + m_end_pc +
78                ", handler_pc = " + m_handler_pc +
79                ", catch_type = " + m_catch_type + ']';
80     }
81      
82     // Cloneable:
83

84     /**
85      * Performs a deep copy.
86      */

87     public Object JavaDoc clone ()
88     {
89         try
90         {
91             return super.clone ();
92         }
93         catch (CloneNotSupportedException JavaDoc e)
94         {
95             throw new InternalError JavaDoc (e.toString ());
96         }
97     }
98       
99     // IClassFormatOutput:
100

101     public void writeInClassFormat (final UDataOutputStream out) throws IOException JavaDoc
102     {
103         out.writeU2 (m_start_pc);
104         out.writeU2 (m_end_pc);
105         out.writeU2 (m_handler_pc);
106         out.writeU2 (m_catch_type);
107     }
108     
109     // protected: .............................................................
110

111     // package: ...............................................................
112

113
114     Exception_info (final UDataInputStream bytes) throws IOException JavaDoc
115     {
116         m_start_pc = bytes.readU2 ();
117         m_end_pc = bytes.readU2 ();
118         m_handler_pc = bytes.readU2 ();
119         m_catch_type = bytes.readU2 ();
120     }
121
122     // private: ...............................................................
123

124 } // end of class
125
// ----------------------------------------------------------------------------
126
Popular Tags