|
SendMessage(message);
Was it that difficult to figure out
only two letters away from being an asset
|
|
|
|
|
Well i have lil doubt about handling exception...
Well i have created a ABCException class based over Exception class.
which includes ABCException class constructors with differnt parameters like..
class STAFException : Exception
{
public ABCException() {...}
public ABCException(Uint32 cc) {...}
public ABCException(Uint32 cc, string message) : base(message) {...}
public ABCException(string message) : base(message){...}
}
Now my question is ... for instance look at the below mentioned method
<br />
public IDictionary createInstance()<br />
{<br />
Hashtable treemap = new Hashtable();<br />
treemap.Add("map-class-name", _mapClassDef["name"]);<br />
return treemap;<br />
}<br />
So if i want to handle its exception...is the below method correct or am i doing it wrong...
<br />
public IDictionary createInstance()<br />
{<br />
try<br />
{<br />
Hashtable treemap = new Hashtable();<br />
treemap.Add("map-class-name", _mapClassDef["name"]);<br />
return treemap;<br />
}<br />
catch(Exception e)<br />
{<br />
throw new ABCException("unknown exception: " + ee.Message);<br />
}<br />
}<br />
<br />
Is it right way to deal with it...can i use this approach with my other methods aswell..?
Thanks
|
|
|
|
|
Software_Specialist wrote: Is it right way to deal with it...can i use this approach with my other methods aswell..?
If you are going to catch an exception and throw a new one you should add the original exception as an innerException to the existing one. That way you'll still have access to the full stack trace. If you don't do that you are throwing away valuable information.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
And how could i do that..how to add the original exception as an innerException to the existing one ?
Thanks
|
|
|
|
|
Call the appropriate base constructor:
Exception(Exception innerException)<br />
Exception(string message, Exception innerException)
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
I love seeing questions like this from some calling themself Software_Specialist. It gives me hope that there is job security for me.
only two letters away from being an asset
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Have you seen the O/S and toys on cell phones lately? What utter crap!
It's only a matter of time before it's simply not worth having your entire customer base pissed at you because you outsourced software development to a company that has too many people who don't know what their doing. At least I hope that's the case!
|
|
|
|
|
Well, Knuth says programming is an art. How many artists you can see around you?
Of course there are several reasons behind this scenario: There is a strong request for software and employers tend to prefer cheap teams; usually Project Managers insist on deadlines more than on software quality; new languages and tools are often presented as accessible to untrained people (and indeed they are, but good programming has NOT such accessibility) and so on...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Well, Knuth says programming is an art.
How true that is!
CPallini wrote: How many artists you can see around you?
I'm alone around here, so I'm the only one. This place has probably given me the most frustrating experience of my life simply supporting all the systems around here. The simplest of ideas are the most difficult concepts to get people to do. I mean stuff we would normally just expect to happen automatically is not being done.
For instance, looking a a trouble ticket that says "Computer not working". That's it! Nothing else! WHICH computer? Who's the contact? Who reported the problem? WHAT'S THE FRIGGIN' PROBLEM DESCRIPTION??
Don't get me started about how people write the code that makes up custom systems around here! Talk about unsupportable...
I wish I could just unload the stories upon the "Coding Horrors" forum, but that would get me fired in a heartbeat.
|
|
|
|
|
CPallini wrote: There is a strong request for software and employers tend to prefer cheap teams
Company executives/managers still haven't heard of the phrase "You get what you pay for"!
|
|
|
|
|
Dave Kreskowiak wrote: Company executives/managers still haven't heard of the phrase "You get what you pay for"!
No, they had. The problem is that they don't get the software, they just sell it to other people
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Dave Kreskowiak wrote: Company executives/managers still haven't heard of the phrase "You get what you pay for"!
maybe it does not apply to executives/managers ?
|
|
|
|
|
Oh, it applies to them most of all!
How many compaines have gone under, run by overpaid executives just tem to fleece the company and the shareholders? Enron, Adelphia, KMart, WorldCom, ...
|
|
|
|
|
On top of the InnerException issue, you should not catch general System.Exception. There are very few cases where this is justified.
Keep in mind that you should only catch exceptions that you know how to deal with or where you can add valuable information before throwing it to the calling code where "someone" will know what to do with it.
If you use catch System.Exception you can be catching any kind of exception that you may have no idea how to handle and that most probably you shouldn't even be trying to handle. In these cases wrapping the exception in your own custom made exception and throwing it does not add any valuable information and is completely pointless, you are only bloating the exception information before it reaches some relevant code.
So, analyse you're class and method and see what type of exceptions you can get that can be handled by your class or where your class can add valuable debugging information to the consumer and catch only those exceptions. If not, just don't catch them at all...the calling code will take care of it, or the caller of the calling, etc, etc.
|
|
|
|
|
NEVER catch an exception that you cannot handle.
In your case, don't catch the ABCException; let it propogate up the call stack. It should be the caller's responsibility to code defensively and handle exceptions.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
i use before HashData function in vb6 which recive array and number as a paramters and generate long integer , i need the eqavalent in c#
Private Declare Function HashData Lib "Util32" (ByRef pbData As Any, ByVal cbData As Long) As Long
please mail me at hosamdahb@yahoo.com
hosam dahb
|
|
|
|
|
it is written something like this
int x=parse.textbox.tex;
|
|
|
|
|
I think it is Int.TryParse(value)
Dan
|
|
|
|
|
int i = int.Parse(textbox.Text);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Er nikesh yadav wrote: it is written something like this
Sorry, I don't see why anyone would need to ask a question like this. Why didn't you read the documentation and see for yourself? Really, this question smacks of sheer laziness.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
As does 99% (statistic provided by my arse) of the questions around here
|
|
|
|
|
Right.
So why answer such questions ?
public void replyToQuestion() {
if (lazy question in topic && nothing useful in body) {
throw up;
}
....
}
|
|
|
|
|
I don't :P
Or I reply with either a sarcastic answer or deliberatly misinterprit what the question is :P
asif_aslam wrote: why we using properties
Origin42 wrote: Because coding outside means getting wet :P
(well it does in this country anyway)
|
|
|
|
|
i am writing a code in C# to use the pda(windows ce)to send messages in a TCP\IP protocol to server using a wifi connection can any one know a refrence that can help me plz any suggestion is approved
Best Wishes
|
|
|
|