Does this count?
-
Would this be better?
if (somethingIsWrong)
{
//handle
}
if (somethingElseIsWrong)
{
//handle
}//Everything is good, we can do the actual work.
Because I don't see the point of throwing a exception only to catch it in the same place. 1: No more negative statements 2: The errors would be something that doesn't deserve exceptions like incorrect input (IIRC) 3: This shouldn't be a problem 4: Don't know
I'm afraid you've missed the joke icon. The coding horrors forum was the right place to put it. :cool:
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
I'm afraid you've missed the joke icon. The coding horrors forum was the right place to put it. :cool:
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
No problem. You'll catch on soon enough. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
Is there a reason for this appearing all over the code???
try
{
if (something is wrong)
throw new exceptionaboutwhateveriswring();
//If nothing was wrong
...
...
...
continue work
}
catch (whatever exception was just thrown)
{
Console.WriteLine(information about the error);
}Sure does. Yeah, that's bad; catching your own exception is like laughing at your own joke. Or other behaviours less kid sister friendly.
-
Is there a reason for this appearing all over the code???
try
{
if (something is wrong)
throw new exceptionaboutwhateveriswring();
//If nothing was wrong
...
...
...
continue work
}
catch (whatever exception was just thrown)
{
Console.WriteLine(information about the error);
} -
Probably written by a VB'r. I have seen that pattern used abundantly.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 3 out now -
Only because C# doesn't support
On Error Resume Next
:((You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4.... -- El Corazon
dan neely wrote:
Only because C# doesn't support On Error Resume Next
Thankfully.
Steve
-
No problem. You'll catch on soon enough. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
"You'll
**catch**
on soon enough" :D.Mark Brock Click here to view my blog
-
Only because C# doesn't support
On Error Resume Next
:((You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4.... -- El Corazon
No, that would be
try
{
// One statement
}
catch
{
// Ignore Exception
} -
No, that would be
try
{
// One statement
}
catch
{
// Ignore Exception
} -
PIEBALDconsult wrote:
// Ignore Exception
Oops, I think you meant,
return null
. ;Pxacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 3 out nowNah, actually I should have had several instances of that construct, but I didn't want to take up much space
try { statement } catch{}
try { statement } catch{}
try { statement } catch{}
try { statement } catch{}
... -
"You'll
**catch**
on soon enough" :D.Mark Brock Click here to view my blog
ooh that's bad haha
-
Is there a reason for this appearing all over the code???
try
{
if (something is wrong)
throw new exceptionaboutwhateveriswring();
//If nothing was wrong
...
...
...
continue work
}
catch (whatever exception was just thrown)
{
Console.WriteLine(information about the error);
}never heard about this? :laugh:
-
Hi, that is a very clever piece of code. The normal approach:
if (!something\_is\_wrong) { // ... do some more } else { // ... show some error message }
has several shortcomings: 1. the tests use negative statements, so they are error prone. 2. the error messages do not include class names and line numbers automatically 3. problems don't get encapsulated in objects 4. it disregards the exception trapping functionality available in Visual Studio So basically it is old style, and against all modern OO principles. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
This is a function of mine, could I get a critique on this? The reason for it being there is because exceptions coming out of the lower level library were not very descriptive or helpful to the guy trying to understand where the config was screwed so this layer was added to get some extra info into the exceptions that were coming up if files were missing and so on. Public Shared Function GetInt(ByVal iniFile As String, ByVal sectionName As String, ByVal keyName As String) As Integer Dim i As Integer Dim ConfigFile As IniConfigSource Dim ConfigSection As IConfig Try 'check file exists If (Not System.IO.File.Exists(iniFile)) Then Throw New Exception("Config file does not exist: " & iniFile) End If 'Access the file ConfigFile = New IniConfigSource(iniFile) 'Get section ConfigSection = ConfigFile.Configs(sectionName) 'check section exists If (IsNothing(ConfigSection)) Then Throw New Exception("Config section does not exist: " & iniFile & vbTab & sectionName) End If 'get key and check it is a valid value Try i = ConfigSection.GetInt(keyName) Catch ex As Exception Throw New Exception("Exception attempting to access integer key: " & iniFile & vbTab & sectionName & vbTab & keyName) End Try Return i Catch ex As Exception 'Exceptions come in here Throw ex End Try End Function