Created
August 1, 2016 06:36
-
-
Save yamamaya/4bf14905e3d0469594630de1d21f968e to your computer and use it in GitHub Desktop.
What exception should I throw?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Sample1 { | |
class Program { | |
static void Main( string[] args ) { | |
Class1 class1 = new Class1(); | |
Console.WriteLine( class1[ DateTime.Now.Second ].ToString() ); | |
} | |
} | |
public class Class1 { | |
public int this[ int x ] { | |
get { | |
if ( x < 10 ) { | |
return x; | |
} | |
// CA1065: Do not raise exceptions in unexpected locations | |
throw new IndexOutOfRangeException( "IndexOutOfRangeException" ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment