Try/catch block...
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
If at first you don't succeed...
-
If at first you don't succeed...
The funniest of all, is that when I was programming that, that I didn't know why I got an error sometimes...
ProgramFOX
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
Makes sense to me. If you're considering stopping reading your e-book and getting some work done, it deals with your crisis of conscience for you.
I wanna be a eunuchs developer! Pass me a bread knife!
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
I'd do it three times, because three is the magic number:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
finally
{
return File.ReadAllText(filename);
}
} -
I'd do it three times, because three is the magic number:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
finally
{
return File.ReadAllText(filename);
}
}If that's C#, it won't compile; you'll get a "Control cannot leave the body of a finally clause" compiler error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
If that's C#, it won't compile; you'll get a "Control cannot leave the body of a finally clause" compiler error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Yes, you are right. So let's remove the last "return" (but not the File.ReadAllText).
-
Makes sense to me. If you're considering stopping reading your e-book and getting some work done, it deals with your crisis of conscience for you.
I wanna be a eunuchs developer! Pass me a bread knife!
Mark Wallace wrote:
If you're considering stopping reading your e-book
But... How can I stop reading my e-book if I'm not reading a e-book?
ProgramFOX
-
Mark Wallace wrote:
If you're considering stopping reading your e-book
But... How can I stop reading my e-book if I'm not reading a e-book?
ProgramFOX
You don't. You throw a
IAmNotReadingAnEBookException
!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
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
It lacks a
while
. -
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
-
If that's C#, it won't compile; you'll get a "Control cannot leave the body of a finally clause" compiler error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
That would compile on java, I think.
-
That would compile on java, I think.
Really? :omg: Which value would expect to be returned here?
try
{
return 1;
}
catch
{
return 2;
}
finally
{
return 42;
}I think the C# compiler is doing the right thing. Either the
return
in thefinally
block is ignored, in which case it shouldn't be allowed, or it replaces any value returned from thetry
orcatch
blocks, which is just confusing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Really? :omg: Which value would expect to be returned here?
try
{
return 1;
}
catch
{
return 2;
}
finally
{
return 42;
}I think the C# compiler is doing the right thing. Either the
return
in thefinally
block is ignored, in which case it shouldn't be allowed, or it replaces any value returned from thetry
orcatch
blocks, which is just confusing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Oh I wasn't saying it should be allowed, but I think it is.
-
Really? :omg: Which value would expect to be returned here?
try
{
return 1;
}
catch
{
return 2;
}
finally
{
return 42;
}I think the C# compiler is doing the right thing. Either the
return
in thefinally
block is ignored, in which case it shouldn't be allowed, or it replaces any value returned from thetry
orcatch
blocks, which is just confusing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
FTSOTR, that does compile in Java (with a little syntactic fix) and returns 42.
-
The funniest of all, is that when I was programming that, that I didn't know why I got an error sometimes...
ProgramFOX
Maybe the file was in use :laugh:
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
-
When I was programming that, I thought: "It's in a catch block, then it can't throw an error!" X|
ProgramFOX
-
I'd do it three times, because three is the magic number:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
finally
{
return File.ReadAllText(filename);
}
}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;
-
I found this in one of my old codes:
public string ReadFile(string filename)
{
try
{
return File.ReadAllText(filename);
}
catch
{
return File.ReadAllText(filename);
}
}:doh:
ProgramFOX
Mmmm... you seem determined to read that file, is it important?
CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...