Rethrowing an exceptionhttp://forums.asp.net/t/315216.aspx/1?Rethrowing+an+exceptionThu, 28 Aug 2003 18:18:48 -0400315216315216http://forums.asp.net/p/315216/315216.aspx/1?Rethrowing+an+exceptionRethrowing an exception Hi maybe I am dumb, I am just new in .net technology. I wonder how can I rethrow an exception in C# .net and in VB.net ?? Thank's 2003-08-21T08:44:24-04:00315228http://forums.asp.net/p/315216/315228.aspx/1?Re+Rethrowing+an+exceptionRe: Rethrowing an exception There is a Throw statement (throw in C#). Catch the exception, and then throw it if you like. 2003-08-21T08:58:21-04:00317785http://forums.asp.net/p/315216/317785.aspx/1?Re+Rethrowing+an+exceptionRe: Rethrowing an exception well in the catch block u can again throw exception by using new operator <pre class="prettyprint">. . catch(Exception e){ thorw (new Exception(&quot;some msg&quot;); } . . . .</pre> u can also store the original exception by assign InnerException property. <pre class="prettyprint"> . . catch(Exception e){ |-----------------------------this is the innerException thorw (new Exception("some msg",e); } . . . . </pre> 2003-08-23T18:56:39-04:00317791http://forums.asp.net/p/315216/317791.aspx/1?Re+Rethrowing+an+exceptionRe: Rethrowing an exception I think it's:<pre class="prettyprint">try { //... } catch (whatever) { throw; //rethrow }</pre>Of course I could be wrong (I've never actually had to use this in C# yet). 2003-08-23T19:10:51-04:00322660http://forums.asp.net/p/315216/322660.aspx/1?Re+Rethrowing+an+exceptionRe: Rethrowing an exception Just for the record, both answers are correct ways to re-throw a caught exception -- the only caveat being that it is almost never appropriate to &quot;eat&quot; the original exception (except possibly in certain scenarios where revealing exception details may have security ramifications like revealing the structure of your SQL tables, or something -- just remember that if you eat the exception, then your customers won't be able to give you the real error message when they report the problem) when throwing from a catch block. You should almost <i>always</i> pass the existing exception to the new one's constructor (and any custom Exception classes you write should allow an inner exception to be passed to the constructor). -- Ryan Milligan 2003-08-28T18:18:48-04:00