• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<!--NewPage-->
3<HTML>
4<HEAD>
5<!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:57 PST 2010 -->
6<TITLE>
7Throwables (Guava Libraries 2010.01.04)
8</TITLE>
9
10<META NAME="date" CONTENT="2010-01-04">
11
12<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
13
14<SCRIPT type="text/javascript">
15function windowTitle()
16{
17    if (location.href.indexOf('is-external=true') == -1) {
18        parent.document.title="Throwables (Guava Libraries 2010.01.04)";
19    }
20}
21</SCRIPT>
22<NOSCRIPT>
23</NOSCRIPT>
24
25</HEAD>
26
27<BODY BGCOLOR="white" onload="windowTitle();">
28<HR>
29
30
31<!-- ========= START OF TOP NAVBAR ======= -->
32<A NAME="navbar_top"><!-- --></A>
33<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
34<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
35<TR>
36<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
37<A NAME="navbar_top_firstrow"><!-- --></A>
38<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
39  <TR ALIGN="center" VALIGN="top">
40  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
41  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
42  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
43  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Throwables.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
44  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
45  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
46  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
47  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
48  </TR>
49</TABLE>
50</TD>
51<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
52</EM>
53</TD>
54</TR>
55
56<TR>
57<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
58&nbsp;<A HREF="../../../../com/google/common/base/Suppliers.html" title="class in com.google.common.base"><B>PREV CLASS</B></A>&nbsp;
59&nbsp;NEXT CLASS</FONT></TD>
60<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
61  <A HREF="../../../../index.html?com/google/common/base/Throwables.html" target="_top"><B>FRAMES</B></A>  &nbsp;
62&nbsp;<A HREF="Throwables.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
63&nbsp;<SCRIPT type="text/javascript">
64  <!--
65  if(window==top) {
66    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
67  }
68  //-->
69</SCRIPT>
70<NOSCRIPT>
71  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
72</NOSCRIPT>
73
74
75</FONT></TD>
76</TR>
77<TR>
78<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
79  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
80<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
81DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
82</TR>
83</TABLE>
84<A NAME="skip-navbar_top"></A>
85<!-- ========= END OF TOP NAVBAR ========= -->
86
87<HR>
88<!-- ======== START OF CLASS DATA ======== -->
89<H2>
90<FONT SIZE="-1">
91com.google.common.base</FONT>
92<BR>
93Class Throwables</H2>
94<PRE>
95<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A>
96  <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.base.Throwables</B>
97</PRE>
98<HR>
99<DL>
100<DT><PRE>public final class <B>Throwables</B><DT>extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL>
101</PRE>
102
103<P>
104Static utility methods pertaining to instances of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang"><CODE>Throwable</CODE></A>.
105<P>
106
107<P>
108<DL>
109<DT><B>Since:</B></DT>
110  <DD>2009.09.15 <b>tentative</b></DD>
111<DT><B>Author:</B></DT>
112  <DD>Kevin Bourrillion, Ben Yu</DD>
113</DL>
114<HR>
115
116<P>
117
118<!-- ========== METHOD SUMMARY =========== -->
119
120<A NAME="method_summary"><!-- --></A>
121<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
122<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
123<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
124<B>Method Summary</B></FONT></TH>
125</TR>
126<TR BGCOLOR="white" CLASS="TableRowColor">
127<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
128<CODE>static&nbsp;<A HREF="http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</A>&lt;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt;</CODE></FONT></TD>
129<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#getCausalChain(java.lang.Throwable)">getCausalChain</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</CODE>
130
131<BR>
132&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets a <code>Throwable</code> cause chain as a list.</TD>
133</TR>
134<TR BGCOLOR="white" CLASS="TableRowColor">
135<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
136<CODE>static&nbsp;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></CODE></FONT></TD>
137<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#getRootCause(java.lang.Throwable)">getRootCause</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</CODE>
138
139<BR>
140&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the innermost cause of <code>throwable</code>.</TD>
141</TR>
142<TR BGCOLOR="white" CLASS="TableRowColor">
143<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
144<CODE>static&nbsp;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
145<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#getStackTraceAsString(java.lang.Throwable)">getStackTraceAsString</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</CODE>
146
147<BR>
148&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a string containing the result of
149 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true#toString()" title="class or interface in java.lang"><CODE>toString()</CODE></A>, followed by the full, recursive
150 stack trace of <code>throwable</code>.</TD>
151</TR>
152<TR BGCOLOR="white" CLASS="TableRowColor">
153<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
154<CODE>static&nbsp;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang">RuntimeException</A></CODE></FONT></TD>
155<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#propagate(java.lang.Throwable)">propagate</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</CODE>
156
157<BR>
158&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagates <code>throwable</code> as-is if it is an instance of
159 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, or else as a last resort, wraps
160 it in a <code>RuntimeException</code> then propagates.</TD>
161</TR>
162<TR BGCOLOR="white" CLASS="TableRowColor">
163<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
164<CODE>static
165<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
166<TR ALIGN="right" VALIGN="">
167<TD NOWRAP><FONT SIZE="-1">
168<CODE>&lt;X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt;
169<BR>
170void</CODE></FONT></TD>
171</TR>
172</TABLE>
173</CODE></FONT></TD>
174<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#propagateIfInstanceOf(java.lang.Throwable, java.lang.Class)">propagateIfInstanceOf</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
175                      <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X&gt;&nbsp;declaredType)</CODE>
176
177<BR>
178&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagates <code>throwable</code> exactly as-is, if and only if it is an
179 instance of <code>declaredType</code>.</TD>
180</TR>
181<TR BGCOLOR="white" CLASS="TableRowColor">
182<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
183<CODE>static&nbsp;void</CODE></FONT></TD>
184<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#propagateIfPossible(java.lang.Throwable)">propagateIfPossible</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</CODE>
185
186<BR>
187&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagates <code>throwable</code> exactly as-is, if and only if it is an
188 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>.</TD>
189</TR>
190<TR BGCOLOR="white" CLASS="TableRowColor">
191<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
192<CODE>static
193<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
194<TR ALIGN="right" VALIGN="">
195<TD NOWRAP><FONT SIZE="-1">
196<CODE>&lt;X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt;
197<BR>
198void</CODE></FONT></TD>
199</TR>
200</TABLE>
201</CODE></FONT></TD>
202<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#propagateIfPossible(java.lang.Throwable, java.lang.Class)">propagateIfPossible</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
203                    <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X&gt;&nbsp;declaredType)</CODE>
204
205<BR>
206&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagates <code>throwable</code> exactly as-is, if and only if it is an
207 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, or
208 <code>declaredType</code>.</TD>
209</TR>
210<TR BGCOLOR="white" CLASS="TableRowColor">
211<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
212<CODE>static
213<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
214<TR ALIGN="right" VALIGN="">
215<TD NOWRAP><FONT SIZE="-1">
216<CODE>&lt;X1 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>,X2 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt;
217<BR>
218void</CODE></FONT></TD>
219</TR>
220</TABLE>
221</CODE></FONT></TD>
222<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#propagateIfPossible(java.lang.Throwable, java.lang.Class, java.lang.Class)">propagateIfPossible</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
223                    <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X1&gt;&nbsp;aDeclaredType,
224                    <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X2&gt;&nbsp;anotherDeclaredType)</CODE>
225
226<BR>
227&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagates <code>throwable</code> exactly as-is, if and only if it is an
228 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, <code>aDeclaredType</code>,
229 or <code>anotherDeclaredType</code>.</TD>
230</TR>
231<TR BGCOLOR="white" CLASS="TableRowColor">
232<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
233<CODE>static&nbsp;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A></CODE></FONT></TD>
234<TD><CODE><B><A HREF="../../../../com/google/common/base/Throwables.html#throwCause(java.lang.Exception, boolean)">throwCause</A></B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A>&nbsp;exception,
235           boolean&nbsp;combineStackTraces)</CODE>
236
237<BR>
238&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rethrows the cause exception of a given throwable, discarding the original
239 throwable.</TD>
240</TR>
241</TABLE>
242&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
243<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
244<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
245<TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH>
246</TR>
247<TR BGCOLOR="white" CLASS="TableRowColor">
248<TD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD>
249</TR>
250</TABLE>
251&nbsp;
252<P>
253
254<!-- ============ METHOD DETAIL ========== -->
255
256<A NAME="method_detail"><!-- --></A>
257<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
258<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
259<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
260<B>Method Detail</B></FONT></TH>
261</TR>
262</TABLE>
263
264<A NAME="propagateIfInstanceOf(java.lang.Throwable, java.lang.Class)"><!-- --></A><H3>
265propagateIfInstanceOf</H3>
266<PRE>
267public static &lt;X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt; void <B>propagateIfInstanceOf</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
268                                                               <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X&gt;&nbsp;declaredType)
269                                  throws X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></PRE>
270<DL>
271<DD>Propagates <code>throwable</code> exactly as-is, if and only if it is an
272 instance of <code>declaredType</code>.  Example usage:
273 <pre>
274   try {
275     someMethodThatCouldThrowAnything();
276   } catch (IKnowWhatToDoWithThisException e) {
277     handle(e);
278   } catch (Throwable t) {
279     Throwables.propagateIfInstanceOf(t, IOException.class);
280     Throwables.propagateIfInstanceOf(t, SQLException.class);
281     throw Throwables.propagate(t);
282   }
283 </pre>
284<P>
285<DD><DL>
286
287<DT><B>Throws:</B>
288<DD><CODE>X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></CODE></DL>
289</DD>
290</DL>
291<HR>
292
293<A NAME="propagateIfPossible(java.lang.Throwable)"><!-- --></A><H3>
294propagateIfPossible</H3>
295<PRE>
296public static void <B>propagateIfPossible</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</PRE>
297<DL>
298<DD>Propagates <code>throwable</code> exactly as-is, if and only if it is an
299 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>.  Example usage:
300 <pre>
301   try {
302     someMethodThatCouldThrowAnything();
303   } catch (IKnowWhatToDoWithThisException e) {
304     handle(e);
305   } catch (Throwable t) {
306     Throwables.propagateIfPossible(t);
307     throw new RuntimeException("unexpected", t);
308   }
309 </pre>
310<P>
311<DD><DL>
312</DL>
313</DD>
314</DL>
315<HR>
316
317<A NAME="propagateIfPossible(java.lang.Throwable, java.lang.Class)"><!-- --></A><H3>
318propagateIfPossible</H3>
319<PRE>
320public static &lt;X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt; void <B>propagateIfPossible</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
321                                                             <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X&gt;&nbsp;declaredType)
322                                throws X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></PRE>
323<DL>
324<DD>Propagates <code>throwable</code> exactly as-is, if and only if it is an
325 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, or
326 <code>declaredType</code>. Example usage:
327 <pre>
328   try {
329     someMethodThatCouldThrowAnything();
330   } catch (IKnowWhatToDoWithThisException e) {
331     handle(e);
332   } catch (Throwable t) {
333     Throwables.propagateIfPossible(t, OtherException.class);
334     throw new RuntimeException("unexpected", t);
335   }
336 </pre>
337<P>
338<DD><DL>
339<DT><B>Parameters:</B><DD><CODE>throwable</CODE> - the Throwable to possibly propagate<DD><CODE>declaredType</CODE> - the single checked exception type declared by the
340     calling method
341<DT><B>Throws:</B>
342<DD><CODE>X extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></CODE></DL>
343</DD>
344</DL>
345<HR>
346
347<A NAME="propagateIfPossible(java.lang.Throwable, java.lang.Class, java.lang.Class)"><!-- --></A><H3>
348propagateIfPossible</H3>
349<PRE>
350public static &lt;X1 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>,X2 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt; void <B>propagateIfPossible</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable,
351                                                                                   <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X1&gt;&nbsp;aDeclaredType,
352                                                                                   <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang">Class</A>&lt;X2&gt;&nbsp;anotherDeclaredType)
353                                throws X1 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>,
354                                       X2 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></PRE>
355<DL>
356<DD>Propagates <code>throwable</code> exactly as-is, if and only if it is an
357 instance of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, <code>aDeclaredType</code>,
358 or <code>anotherDeclaredType</code>.  In the unlikely case that you have three
359 or more declared checked exception types, you can handle them all by
360 invoking these methods repeatedly. See usage example in
361 <A HREF="../../../../com/google/common/base/Throwables.html#propagateIfPossible(java.lang.Throwable, java.lang.Class)"><CODE>propagateIfPossible(Throwable, Class)</CODE></A>.
362<P>
363<DD><DL>
364<DT><B>Parameters:</B><DD><CODE>throwable</CODE> - the Throwable to possibly propagate<DD><CODE>aDeclaredType</CODE> - any checked exception type declared by the calling
365     method<DD><CODE>anotherDeclaredType</CODE> - any other checked exception type declared by the
366     calling method
367<DT><B>Throws:</B>
368<DD><CODE>X1 extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A></CODE></DL>
369</DD>
370</DL>
371<HR>
372
373<A NAME="propagate(java.lang.Throwable)"><!-- --></A><H3>
374propagate</H3>
375<PRE>
376public static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang">RuntimeException</A> <B>propagate</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</PRE>
377<DL>
378<DD>Propagates <code>throwable</code> as-is if it is an instance of
379 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/RuntimeException.html?is-external=true" title="class or interface in java.lang"><CODE>RuntimeException</CODE></A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Error.html?is-external=true" title="class or interface in java.lang"><CODE>Error</CODE></A>, or else as a last resort, wraps
380 it in a <code>RuntimeException</code> then propagates.
381 <p>
382 This method always throws an exception. The <code>RuntimeException</code> return
383 type is only for client code to make Java type system happy in case a
384 return value is required by the enclosing method. Example usage:
385 <pre>
386   T doSomething() {
387     try {
388       return someMethodThatCouldThrowAnything();
389     } catch (IKnowWhatToDoWithThisException e) {
390       return handle(e);
391     } catch (Throwable t) {
392       throw Throwables.propagate(t);
393     }
394   }
395 </pre>
396<P>
397<DD><DL>
398<DT><B>Parameters:</B><DD><CODE>throwable</CODE> - the Throwable to propagate
399<DT><B>Returns:</B><DD>nothing will ever be returned</DL>
400</DD>
401</DL>
402<HR>
403
404<A NAME="getRootCause(java.lang.Throwable)"><!-- --></A><H3>
405getRootCause</H3>
406<PRE>
407public static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A> <B>getRootCause</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</PRE>
408<DL>
409<DD>Returns the innermost cause of <code>throwable</code>. The first throwable in a
410 chain provides context from when the error or exception was initially
411 detected. Example usage:
412 <pre>
413   assertEquals("Unable to assign a customer id",
414       Throwables.getRootCause(e).getMessage());
415 </pre>
416<P>
417<DD><DL>
418</DL>
419</DD>
420</DL>
421<HR>
422
423<A NAME="getCausalChain(java.lang.Throwable)"><!-- --></A><H3>
424getCausalChain</H3>
425<PRE>
426public static <A HREF="http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</A>&lt;<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&gt; <B>getCausalChain</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</PRE>
427<DL>
428<DD>Gets a <code>Throwable</code> cause chain as a list.  The first entry in the
429 list will be <code>throwable</code> followed by its cause hierarchy.  Note
430 that this is a snapshot of the cause chain and will not reflect
431 any subsequent changes to the cause chain.
432
433 <p>Here's an example of how it can be used to find specific types
434 of exceptions in the cause chain:
435
436 <pre>
437 Iterables.filter(Throwables.getCausalChain(e), IOException.class));
438 </pre>
439<P>
440<DD><DL>
441<DT><B>Parameters:</B><DD><CODE>throwable</CODE> - the non-null <code>Throwable</code> to extract causes from
442<DT><B>Returns:</B><DD>an unmodifiable list containing the cause chain starting with
443     <code>throwable</code></DL>
444</DD>
445</DL>
446<HR>
447
448<A NAME="getStackTraceAsString(java.lang.Throwable)"><!-- --></A><H3>
449getStackTraceAsString</H3>
450<PRE>
451public static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>getStackTraceAsString</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true" title="class or interface in java.lang">Throwable</A>&nbsp;throwable)</PRE>
452<DL>
453<DD>Returns a string containing the result of
454 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true#toString()" title="class or interface in java.lang"><CODE>toString()</CODE></A>, followed by the full, recursive
455 stack trace of <code>throwable</code>. Note that you probably should not be
456 parsing the resulting string; if you need programmatic access to the stack
457 frames, you can call <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html?is-external=true#getStackTrace()" title="class or interface in java.lang"><CODE>Throwable.getStackTrace()</CODE></A>.
458<P>
459<DD><DL>
460</DL>
461</DD>
462</DL>
463<HR>
464
465<A NAME="throwCause(java.lang.Exception, boolean)"><!-- --></A><H3>
466throwCause</H3>
467<PRE>
468public static <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A> <B>throwCause</B>(<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A>&nbsp;exception,
469                                   boolean&nbsp;combineStackTraces)
470                            throws <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A></PRE>
471<DL>
472<DD>Rethrows the cause exception of a given throwable, discarding the original
473 throwable. Optionally, the stack frames of the cause and the outer
474 exception are combined and the stack trace of the cause is set to this
475 combined trace. If there is no cause the original exception is rethrown
476 unchanged in all cases.
477<P>
478<DD><DL>
479<DT><B>Parameters:</B><DD><CODE>exception</CODE> - the exception from which to extract the cause<DD><CODE>combineStackTraces</CODE> - if true the stack trace of the cause will be
480     replaced by the concatenation of the trace from the exception and the
481     trace from the cause.
482<DT><B>Throws:</B>
483<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</A></CODE></DL>
484</DD>
485</DL>
486<!-- ========= END OF CLASS DATA ========= -->
487<HR>
488
489
490<!-- ======= START OF BOTTOM NAVBAR ====== -->
491<A NAME="navbar_bottom"><!-- --></A>
492<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
493<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
494<TR>
495<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
496<A NAME="navbar_bottom_firstrow"><!-- --></A>
497<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
498  <TR ALIGN="center" VALIGN="top">
499  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
500  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
501  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
502  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Throwables.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
503  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
504  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
505  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
506  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
507  </TR>
508</TABLE>
509</TD>
510<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
511</EM>
512</TD>
513</TR>
514
515<TR>
516<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
517&nbsp;<A HREF="../../../../com/google/common/base/Suppliers.html" title="class in com.google.common.base"><B>PREV CLASS</B></A>&nbsp;
518&nbsp;NEXT CLASS</FONT></TD>
519<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
520  <A HREF="../../../../index.html?com/google/common/base/Throwables.html" target="_top"><B>FRAMES</B></A>  &nbsp;
521&nbsp;<A HREF="Throwables.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
522&nbsp;<SCRIPT type="text/javascript">
523  <!--
524  if(window==top) {
525    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
526  }
527  //-->
528</SCRIPT>
529<NOSCRIPT>
530  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
531</NOSCRIPT>
532
533
534</FONT></TD>
535</TR>
536<TR>
537<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
538  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
539<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
540DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
541</TR>
542</TABLE>
543<A NAME="skip-navbar_bottom"></A>
544<!-- ======== END OF BOTTOM NAVBAR ======= -->
545
546<HR>
547
548</BODY>
549</HTML>
550