473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

differnece b/w Throw; and Throw ex ; where ex is Expection Object


the code goes some thing like this

try
{
some statements;
}
catch(Exception ex)
{
throw;
}

try
{
some statements;
}
catch(Exception ex)
{
throw ex;
}

Oct 30 '06 #1
2 1126

The first (throw;) preserves the stack trace of ex, the latter does
not.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 30 '06 #2
To add to Mattias' statments with some general guidelines.

First, do not catch to simply throw. If you cannot do anything with the
exception, let it pass up the stack. You do have to catch before UI, to
avoid showing the user the error, but if you are not doing something with
the exception or attempting to fix it, try ... finally is a better pattern.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"deepak" <ts******@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
the code goes some thing like this

try
{
some statements;
}
catch(Exception ex)
{
throw;
}

try
{
some statements;
}
catch(Exception ex)
{
throw ex;
}

Oct 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ritche | last post by:
I have a redirect page using PerlScript titled clickthru.asp: <%@LANGUAGE="PerlScript"%> <% my $url = $Request->QueryString('url')->Item(); $Response->Redirect($url); %> I keep running into...
2
by: Cheng Mo | last post by:
Below code cannot be compiled. try { throw std::string; } catch(...) { } While below is correct.
6
by: Arjen | last post by:
Hi, I'm reading the enterprise library documentation and there I see the throw statement. try { // run code } catch(Exception ex) {
1
by: Sefner | last post by:
Hey everyone. I have a program that watches a .txt log file from a chat client or a game and based on each line, triggers events. One thing I am trying to do is send the contents of a text file to...
3
by: Curious | last post by:
What is the difference between: catch(Exception e) { throw e; } and catch(Exception e) { throw; }
28
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
1
by: shapper | last post by:
Hello, I have a function named Find as follows: Public Function Find() As Control Dim AllControls As Control() = FindAll() End Function FindAll returns can return an array of controls or...
21
by: Agustin Villena | last post by:
Hi! is there anyway to show the class of a method in an exception's traceback? For example, the next code class Some(object): def foo(self,x): raise Exception(x)
10
by: arvindkuk | last post by:
how to work with expection handing in which when i am using try block then the error message coming that "undefined symbol try" why it is so, please solve my problem.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.