Skip to content

Instantly share code, notes, and snippets.

@yamamaya
Created August 1, 2016 06:36
Show Gist options
  • Save yamamaya/4bf14905e3d0469594630de1d21f968e to your computer and use it in GitHub Desktop.
Save yamamaya/4bf14905e3d0469594630de1d21f968e to your computer and use it in GitHub Desktop.
What exception should I throw?
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