﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum / General .NET Discussion / .NET Forums  / Throwing exception question... / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>forum@strataframe.net</webMaster><lastBuildDate>Fri, 21 Nov 2008 14:42:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Throwing exception question...</title><link>http://forum.strataframe.net/Topic2170-14-1.aspx</link><description>Yes, it does also apply to VB.NET.  You can use Throw without specifying the exception to keep it from clearing the stack trace.</description><pubDate>Fri, 11 Aug 2006 16:44:33 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>Throwing exception question...</title><link>http://forum.strataframe.net/Topic2170-14-1.aspx</link><description>Here is an excerpt from a book called: "Visual Studio .NET Tips and Tricks" By Minh T. Nguyen&lt;br&gt;&lt;br&gt;Rethrowing the Same Exception &lt;br&gt;&lt;br&gt;Whenever an exception needs to be logged, developers tend to use code similar to the &lt;br&gt;following to log an exception without eating it up: &lt;br&gt;&lt;br&gt;Try &lt;br&gt;{...}&lt;br&gt;catch (Exception ex) { &lt;br&gt;Log(ex);&lt;br&gt;throw ex; &lt;br&gt;}&lt;br&gt;&lt;br&gt;This code works, and the exception won’t be eaten up because it’s being rethrown at the end. However, developers don’t often realize that rethrowing the same exception in this way causes .NET to clear the exception’s stack trace. When you inspect the exception’s stack trace property it will seem as though the exception was originally thrown for the first time inside that catch block.&lt;br&gt;&lt;br&gt;To throw the same exception correctly in a catch block, simply use “throw;” as follows: &lt;br&gt;Try &lt;br&gt;{...}&lt;br&gt;catch (Exception ex) { &lt;br&gt;Log(ex);&lt;br&gt;throw; &lt;br&gt;}&lt;br&gt;&lt;br&gt;This rethrows the same exception that was just caught without clearing the stack trace.&lt;br&gt;&lt;br&gt;His example is in C++ or C#... does what he's saying also apply to VB .NET?&lt;br&gt;&lt;br&gt;Thanks</description><pubDate>Fri, 11 Aug 2006 16:21:02 GMT</pubDate><dc:creator>StarkMike</dc:creator></item></channel></rss>