|
What is the difference between
try { } catch { throw; }
and
try { } catch(Exception e) { throw e;}
and when should i use one or another?
Started by Karim on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
You should use
try { } catch(Exception e) { throw }
if you want to do something with the exception before ....
Catch (Exception ex) { throw new Exception("Additional information...", ex); }
There's a blog post discussing the differences.
|
|
The title really is the question for this one: Is there an equivalent in T-SQL to C#'s "throw;" to re-throw exceptions?
In C# one can do this:
try { DoSomethingThatMightThrowAnException(); } catch (Exception ex) { // Do something with the exception throw...
Started by Neil Barnwell on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
); END CATCH;
EDIT:
This is not really the same thing as c#'s throw or throw ex.
State.
|
|
There are some posts that asks what the difference between those two are already.
(why do I have to even mention this...)
But my question is different in a way that I am calling "throw ex" in another error god-like handling method.
public class Program...
Started by Sung Meister on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
No, this will cause the exception to have a different... .
Yes, there is a difference;
throw ex resets the stack trace (so your errors would appear to originate from HandleException ) throw doesn't - the original offender would be preserved.
|
Ask your Facebook Friends
|
Imagine two similar pieces of code:
try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw err; }
and
try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw; }
Are these effectively the same or...
Started by WilliamKF on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
In the second case according to C++ Standard 15.1/6 copy constructor is not used:
A throw exception will be thrown according to 15.1/3:
A throw-expression initializes a temporary object from the static type of the operand of throw....
|
|
I'd like to ask this question (also here ), but this time about C++.
What is the difference in C++ between
try { /*some code here*/} catch(MyException& ex) { throw ex;}
and
try { /*some code here*/} catch(MyException& ex) { throw;}
Is it just in the stack...
Started by Joshua Fox on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
You can use the throw; form with catch(...) (that is it is the only way to rethrow if you caught using catch(...) )....
throw ex will make another copy and is not recommend use throw only to throw the current exception object.
|
|
In Java, what is the difference between the twin methods?
public void methodA() throws AnException { //do something throw new AnException(); } public void methodA() { //do the same thing throw new AnException(); }
I have a intuition that it has something...
Started by Martin on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Aside from the good answers given by others about.
The javadoc for your method will show that it might throw advanced setup for functions that throw exceptions.
In this case, for the reasons of documentation.
|
|
Here's the setup.
I have a C++ program which calls several functions, all of which potentially throw the same exception set, and I want the same behaviour for the exceptions in each function (e.g. print error message & reset all the data to the default...
Started by deworde on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
In this case, the standard (see section 15.5.1) specifies that
If... .
If you use throw outside of an exception, you will throw without an exception being handled.
If you use throw inside of a catch block, it will rethrow the exception.
|
|
I was digging around in MSDN and found this article which had one interesting bit of advice: Do not have public members that can either throw or not throw exceptions based on some option.
For example:
Uri ParseUri(string uriValue, bool throwOnError)
Now...
Started by cbp on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Developers tend to expect every method to throw an exception exception so that I can catch it later....
Namely because it requires of nasty from a readabilty standpoint .
Idea to have a throw / no throw decision be based off of a boolean.
|
|
Whenever I throw an exception in my service, another exception is thrown right after it:
System.ServiceModel.CommunicationException: There was an error reading from the pipe: Unrecognized error 109 (0x6d). ---> System.IO.PipeException: There was an...
Started by Meidan Alon on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
How to enable this: check this site: link text
Problem was client calling Abort on the channel whenever I returned a fault exception. .
Try to enable tracing why you have a communication error .
|
|
Std::exception class is defined as follows
exception() throw() { } virtual ~exception() throw(); virtual const char* what() const throw();
what does the throw() syntax mean in a declaration? Can throw() take parameters? What does no parameters mean?
Answer Snippets (Read the full thread at stackoverflow):
No arguments means that the function can't ....
If you specify anything as a parameter, you're saying that the function will throw only exceptions .
Without any parameter, it means that the mentioned functions does not throw any exceptions.
|