|
Richard Deeming wrote: If that's C#, it won't compile; you'll get a "Control cannot leave the body of a finally clause" compiler error. I had to play around. You can throw an error in the try/catch/finally segments and it will compile. Since I didn't enclose the routine in a try catch, the finally segment did blow up with an unhandled exception. Then I did put it in that logic:
try
{
int junk = trycat();
}
catch (Exception ex)
{
Console.WriteLine("caught exception {0}", ex.Message);
Console.ReadKey();
}
...
static int trycat()
{
try
{
throw (new Exception("Throwing an exception in try block"));
}
catch
{
throw (new Exception("Throwing an exception in catch block"));
}
finally
{
throw (new Exception("Throwing an exception in finally block"));
}
return 1;
}
|
|
|
|
|
Sigh.
public string ReadFile(string filename)
{
string contents = null;
try
{
contents = File.ReadAllText(filename);
}
catch
{
contents = File.ReadAllText(filename);
}
finally
{
contents = File.ReadAllText(filename);
}
return contents;
} Okay. Everybody happy now?
Software Zen: delete this;
|
|
|
|
|
Quitter - use recursion!
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return ReadFile(filename);
}
}
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
|
|
|
|
|
brisingr@gryphon-pc$ cpmsg --process --msg "4433493" --forum "The Weird and The Wonderful" --code "Process"
ERROR: StackOverflowException was encountered.
brisingr@gryphon-pc$|
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
Maybe we need a more flippant programming language, for those of us who think like this:
try
{
// something
}
ifatfirstyoudontsucceed
{
// try again
}
thirdtimelucky
{
// and again
}
giveup // synonym for catch
{
// error handling
}
finally
{
// tidying up
}
|
|
|
|
|
Bernhard Hiller wrote: three is the magic number
It sure is!
Monty Python :
First shalt thou take out the Holy Pin.
Then, shalt thou count to three, no more, no less.
Three shalt be the number thou shalt count, and the number of the counting shall be three.
Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three.
Five is right out.
Once the number three, being the third number, be reached, then lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who, being naughty in my sight, shall snuff it."
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
|
I like it. Another opportunity to bill the client.
|
|
|
|
|
|
When I was programming that, I thought: "It's in a catch block, then it can't throw an error!"
ProgramFOX
|
|
|
|
|
Mmmm... you seem determined to read that file, is it important?
|
|
|
|
|
No. The reading of the file isn't important.
That's a code from 2 years ago.
Now, I know how I can read files!
ProgramFOX
|
|
|
|
|
Timed out first time, then worked the second time?
|
|
|
|
|
ALTER PROCEDURE [dbo].[arUpdate]
@intForecastID int,
@strForecastName varchar(18),
@strBillTo varchar(12),
@strPOCName varchar(50),
@strPOCEmail varchar(100),
@strModifiedBy varchar(20),
@strComment varchar(3000),
@strDelMaterials varchar(8000),
@strData1 varchar(8000),
@strData2 varchar(8000),
@strData3 varchar(8000),
@strData4 varchar(8000),
@strData5 varchar(8000),
@strData6 varchar(8000),
@strData7 varchar(8000),
@strData8 varchar(8000),
@strData9 varchar(8000),
@strData10 varchar(8000),
@strData11 varchar(8000),
@strData12 varchar(8000),
@strData13 varchar(8000),
@strData14 varchar(8000),
@strData15 varchar(8000),
@strData16 varchar(8000),
@strData17 varchar(8000),
@strData18 varchar(8000),
@strData19 varchar(8000),
@strData20 varchar(8000)
None of the code in this procedure or from the calling methods looked any better. The data going into the varchar(8000) fields was delimited with a grab bag combination of special characters. Which was then pealed apart using cursors.
|
|
|
|
|
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
What if I want @strData21 varchar(8000) ?
If you don't think this is a serious question then you should have a chat with a lass in our office. According to her a DB server handling a load of 1 select query a second is being DDOS'd and the answer to this non-problem is to select all from every single table in the database on application startup and perform all paging and sorting in memory..
|
|
|
|
|
Hey it sounds like she's onto something, let's pin all of our mission critical data to the table and give it a wild night it won't forget!
Or you could go to mongoDB. MongoDB is web-scale mongo db can pipe all your data to /dev/null to ensure lightning fast performance.
Just a question for said girl, if I try to read too many files from a slow, mechanical hard-drive and I cause thrashing, am I DDOS'ing my HD
I want to put the fun back into fundamentalism!
|
|
|
|
|
Back slowly away. This was obviously the work of a Sociopath.
|
|
|
|
|
Unfortunately, such people insist on calling them programmers. Gives our profession a bad name ...
|
|
|
|
|
I have that exact same pattern in my DB(not done by me), i wonder if they were both written by the same person. In my version though all those varchar(8000)s are ignored in the first SP and passed to a second which does even more string manipulation with cursors. wonder why they just didnt use one varchar(max) or a text field.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
SomeGuyThatIsMe wrote: wonder why they just didnt use one varchar(max) or a text field.
I'd guess this was written in SQL 2000. max didn't exist and it took too much thinking to do character manipulation on text fields. (For anyone who'd write this in the first place.)
I can't picture how to execute a cursor on a varchar field. (Extract a fraction of the data and then use a cursor to retrieve it from a table, sure, but ON the field?)
|
|
|
|
|
If i find the time today i'll post that piece of the sp.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Because people are still looking for a silver-bullet, 1 thing that can do everything for you. Would hate to see the design & architecture of the rest of the 'solution'
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
Design? Architecture? Not on this project man!
|
|
|
|
|
Because the person who wrote it likes to curl up in a small ball with a nervous twitch in their eye whilst they inappropriately touch a small fury animal.
Honestly, you're better not asking, pretend you never saw it and maybe, just maybe, you'll make it through to tomorrow with a shred of sanity left in you.
Eagles may soar, but weasels don't get sucked into jet engines
|
|
|
|