try { throw new ArgumentException("some operation that throws an exception"); string s = "blah"; } catch (e as ArgumentException) { Console.Out.WriteLine(s); }
public void printStackTrace() { printStackTrace(System.err); }
public void printStackTrace() { printStackTrace(System.err); }
if (seed1 >= 1 || seed1 < 0) throw new ArgumentException("Seed 1 must be >= 0 and < 1, not " + seed1); prevNum = seed1; if (seed2 <= 1 || seed2 > 10) throw new ArgumentException("Seed 2 must be > 1 and <= 10, not " + seed2); magicNumber = seed2;
public void printStackTrace() { printStackTrace(System.err); }
throw new ArgumentException("A cannot have 0 elements", "A");
public void printStackTrace() { printStackTrace(System.err); }
throw new ArgumentException("strengthInBits must be evenly divisible by 8.", "strengthInBits");
public void printStackTrace() { printStackTrace(System.err); }
throw new ArgumentException();
throw new ArgumentException( "Expression must be a simple property expression." );
int n = itemsList.Count; if (n < 1) throw new ArgumentException("Must contain at least one item.", "items"); if (choose <= 0 || choose >= n) throw new ArgumentOutOfRangeException("choose");
public void DoThis(Something thing) { if (thing == null) { throw new ArgumentException("Arg [thing] cannot be null."); } //... }
public MyClass(int a, int b, int c) { if(c != 1 && c != 2) throw new ArgumentException(...); ... }
public class Test { public void DoSomething(Type myClass) { if(!typeof(Test).IsAssignableFrom(myClass)) { throw new ArgumentException("myClass must refer to Test or a derived class", "myClass"); } } }
public void changeArcName(String x) { if (x == null) throw new ArgumentException ("x is null!"); this.arcName = x; }
public class PdfController : Controller { [HttpGet] public ActionResult View(Guid id) { if (id == Guid.Empty || id == null) throw new ArgumentException("id null or emtpy", "id"); using (var serviceClient = ServiceClient.GetAuthClient<ArchiveDocumentServiceClient, IArchiveDocumentService>()) { var archiveDocument = serviceClient.GetById(id); if (archiveDocument == null) throw new ApplicationException("ArchiveDocument not found."); Response.Headers.Remove("Content-Disposition"); Response.Headers.Add("Content-Disposition", "inline; filename=" + archiveDocument.Document.Name); return File(archiveDocument.Document.DocumentData, "application/pdf"); } } }
IEnumerable<IEnumerable<int>> generatePermutations(int length) { if (length <= 0) throw new ArgumentException(); var resultCollection = new List<IEnumerable<int>> { new [] { 0 } }; for (var index = 1; index < length; index++) { var newResultCollection = new List<IEnumerable<int>>(); foreach (var result in resultCollection) { for (var insertIndex = index; insertIndex >= 0; insertIndex--) { var list = new List<int>(result); list.Insert(insertIndex, index); newResultCollection.Add(list); } } resultCollection = newResultCollection; } return resultCollection; }
public class MyType { // Your type here } public class MyTypeCollection : ArrayList { public override int Add(object value) { if (!(value is MyType)) { throw new ArgumentException("value must be of type MyType"); } return base.Add(value); } public int Add(MyType myType) { return base.Add(myType); } // Other overrides here }
DateTime UnixEpochBaseDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); Int64 ToUnixTime(DateTime utcValue) { if (utcValue.Kind != DateTimeKind.Utc) throw new ArgumentException("Value must be in Utc."); var result = (utcValue - UnixEpochBaseDate).Ticks / TimeSpan.TicksPerMillisecond; return result; }