leppie wrote: Not if you use it correctly. For example, to abort a thread at a precise point and raise an "event".
It still sounds like a dodgy idea. What if something else in the try block throws an exception for another reason? I suppose it's possible to make sure that doesn't happen.
I assume you're trying to kick out of a loop? Isn't there a better way, like "break"?
Just thinking aloud. It strikes me that there should be a way to do this without using an exception, but maybe not. (tell me to stop being nosey, if you want )
Paul Riley wrote: I assume you're trying to kick out of a loop? Isn't there a better way, like "break"?
Probably, but I needed to send some arguements with the "event", and this was the quickest thing that came to mind. The nice thing is I didnt have to implement an event or had to add/remove a handler. Only a try/catch, for when (if) it happens.
Let me put it this way: I used to work with COBOL and some of the worst code I've ever seen was as a direct result of people trying at all costs to avoid using GO TO.
I mean okay, I understand why GO TO is considered tacky but in COBOL at times it can be absolutely necessary because there aren't any other construct-breakers.
So I do accept that sometimes what may be considered tacky is actually the neatest thing to do.
I will say this though: don't avoid implementing events. Once you've done two or three, you get used to them and you can knock them together in a couple of minutes. I love events
OK, I do agree, events are the nicer way, but if a tree falls in the forest when nobody's there to hear it, will it make a sound? The was just to test some thing quick(and dirty). I dont I will every let people see such a thing.
Paul Riley wrote: Once you've done two or three, you get used to them and you can knock them together in a couple of minutes.
Unfortunately, most people can do events, but have no idea what is happening under the hood. Once you understand delegates though, things do become very clear and easy.
leppie wrote: OK, I do agree, events are the nicer way, but if a tree falls in the forest when nobody's there to hear it, will it make a sound?
Yes.
leppie wrote: Unfortunately, most people can do events, but have no idea what is happening under the hood. Once you understand delegates though, things do become very clear and easy.
Absolutely true. It's one thing to copy it out of a book as I did with my first event, it's something else entirely to figure out what a delegate is and use it properly.
It really is a surprisingly simple concept when you get your head around it though (surprising because it took me hours to understand it but then when I did I wondered why it took me so long).
Erik Westermann wrote: Simply becasue the idea of the .NET Platofrm is to provide a space where all activities occur in a managed, type-safe environment. The System namespace is called "system" becuase it exposes classes that you can use to interact with the "system". If your applicaiton throws an exception, throw an applicaiton-specific exception that's derived from System.ApplicationException to avoid confusion with CLR-generated exceptions.
But wouldn't this be a problem in itself? Let's say you write a program, that uses class libraries from two or three different vendors and each throws a different kind of exception if the exact same condition (an argument is set to null for example) is met? Wouldn't this be a bad design, too? And why is it more exceptional if you pass an invalid "null" argument to a clr function than to a function of a third party library? I see the point with the out of memory exception - that sure is some kind of "system exception". But ArgumentNullException and ArgumentOutOfRange exception? Actually I never thought about these problems (Visual C# step by step at least uses these two exceptions in user code) - only wether it is the right exception to be thrown from a set accessor.
Martin Häsemeyer wrote: Wouldn't this be a bad design, too?
How so? You know the exact nature of the problem based on the exception's type. Besides, all exceptions are derivatives of System.Exception; as a result, if you code your catch blocks properly, you'll be able to handle errors from both libraries in this scenario.
Martin Häsemeyer wrote: And why is it more exceptional if you pass an invalid "null" argument to a clr function than to a function of a third party library?
It isn't. It depands on what the class' designer is atembpting to achieve. An exception is designed to, ultimately, halt your code if it is allowed to 'bubble up' through to the system regardless of what type of exception gets thrown. Exceptons are non-local control structures that let you centralize error handling in one part of your application as opposed to having you sprinkle if statements throughout your code. In some cases; however, it is more approprate a number of cases to use a less computationally expensive means of handling an error.
Erik Westermann
Author, Learn XML In A Weekend (October 2002)
Erik Westermann wrote: Exceptions are for exceptional conditions - conditions that are unexpected during normal circumstances. Exceptions are relatively expensive and aren't that great for stuff like this.
I was just watching the latest .Net show off MSDN and it is all about performance. One of the things they where saying is Exceptions are only expensive if you acctually throw the exception. This makes them very good for doing this sort of thing.
I want to lighten/darken the shade of a given color. I just wondered if there was a better way, than just adding/substracting an amout from each RGB value, because it in some cases, the difference in color is minute.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site. Support for development will ship at the same time as the Windows XP Service Pack 1 (SP1) release.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site. Support for development will ship at the same time as the Windows XP Service Pack 1 (SP1) release.
I'm sure you can use bits of it but I'm not sure why you'd want to. You certainly can't (ar at the very least shouldn't) display a Windows Forms control on a web page.
I'm working on a small app that scrapes some HTML and parses out a few data items.
(specifically: I am trying to snag the 2 values for Total CPU Time (4:217:02:06:36) and Ranking (# 2,313) contined in the sniped below)
<br />
<tr bgcolor="#FFFFFF" onmouseover="javascript:style.background='#E5E5E5'" onmouseout="javascript:style.background='#FFFFFF'"><br />
<td>Total CPU Time (y:d:h:m:s) (Rank)</td><br />
<td nowrap="true">4:217:02:06:36(# 2,313)</td><br />
</tr><br />
Any suggestions on HOW? I am assuming that a RegExp might be the easiest, but I'm no wizard at creating those (i.e. any suggestions/help would be appreciated).
I want to make an automatic update system. Here is my simple plan for one:
At the begining of application init, the application will go into the updater block.
//////// Updater block psedo code
settings = Load application settings;
if (user wants auto updates)
{
//creat an instance of the updater from a library Updater.dll
Updater myUpdater = new Updater();
// updater goes online and check for updates
UpdaterFeedback = myUpdater.StartUpdater();
if (updaterfeedback == updatefound)
{
if (settings.totallyautomatic == true)
{
updater.doupdater
}
else
{
// ask user if they want to update & tell them about the update
// also give them some info on it
if (userWantsToUpdate == true)
{
updater.DoUpdate();
}
}
}
}
else
{
continue with the application startup
}
//////// End updater block
----------------------------
If you have any ideas, please post them
I have not a clue how to do the internet update check, if you have any ideas please post them.
well you could use the WebRequest classes to read a txt file from the net that has the latest version number for the app, and if not, downmload the new file. i cannot offer any more help on the matter, and next time, try thinking about it, istead of asking someone to write it for you, if you get stuck on a particular aspect of it, then we'll be more than happy to help.