try { throw new ArgumentException("some operation that throws an exception"); string s = "blah"; } catch (e as ArgumentException) { Console.Out.WriteLine(s); }
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;
throw new ArgumentException("A cannot have 0 elements", "A");
throw new ArgumentException("strengthInBits must be evenly divisible by 8.", "strengthInBits");
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(...); ... }
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; }
// convert DateTime to string return DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture); // convert string to DateTime if(value.Length != 14) throw new ArgumentException("Value must be 14 characters."); int year = Int32.Parse(value.Substring(0, 4)); int month = Int32.Parse(value.Substring(4,2)); int day = Int32.Parse(value.Substring(6,2)); int hour = Int32.Parse(value.Substring(8,2)); int minute = Int32.Parse(value.Substring(10,2)); int second = Int32.Parse(value.Substring(12,2)); return new DateTime(year, month, day, hour, minute, second, 0);
public bool CanBuild(SetOfData<SomeType> setofdata) { return validator.IsValid(setofdata); } public BusinessObject Build(SetOfData<SomeType> setofdata) { if (validator.IsValid(setofdata)) { return new BusinessObject(setofdata); } throw new ArgumentException(); }
/** * Translate the javax.persistence enum value to our internal lock level. */ static int toLockLevel(LockModeType mode) { if (mode == null) return LockLevels.LOCK_NONE; if (mode == LockModeType.READ) return LockLevels.LOCK_READ; if (mode == LockModeType.WRITE) return LockLevels.LOCK_WRITE; throw new ArgumentException(mode.toString(), null, null, true); }
/** * Translate a flush mode enum value to our internal flush constant. */ static int toFlushBeforeQueries(FlushModeType flushMode) { // choose default for null if (flushMode == null) return QueryFlushModes.FLUSH_WITH_CONNECTION; if (flushMode == FlushModeType.AUTO) return QueryFlushModes.FLUSH_TRUE; if (flushMode == FlushModeType.COMMIT) return QueryFlushModes.FLUSH_FALSE; throw new ArgumentException(flushMode.toString(), null, null, false); }
private void validateParameter(String paramDesc, Class type, Object param) { // null parameters are allowed, so are not validated if (param == null || type == null) return; // check the parameter against the wrapped type if (!Filters.wrap(type).isInstance(param)) throw new ArgumentException(_loc.get("bad-param-type", paramDesc, param.getClass().getName(), type.getName()), null, null, false); }
/** * Validate that the user provided SQL. */ protected void validateSQL(String query) { if (StringUtils.trimToNull(query) == null) throw new ArgumentException(_loc.get("no-sql"), null, null, false); }
/** * Validate that the user provided SQL. */ protected void validateSQL(String query) { if (StringUtil.trimToNull(query) == null) throw new ArgumentException(_loc.get("no-sql"), null, null, false); }
/** * Validate that the user provided SQL. */ protected void validateSQL(String query) { if (StringUtil.trimToNull(query) == null) throw new ArgumentException(_loc.get("no-sql"), null, null, false); }
public boolean contains(Object entity) { assertNotCloseInvoked(); if (entity == null) return false; OpenJPAStateManager sm = _broker.getStateManager(entity); if (sm == null && !ImplHelper.isManagedType(getConfiguration(), entity.getClass())) throw new ArgumentException(_loc.get("not-entity", entity.getClass()), null, null, true); return sm != null && !sm.isDeleted(); }
public boolean contains(Object entity) { assertNotCloseInvoked(); if (entity == null) return false; OpenJPAStateManager sm = _broker.getStateManager(entity); if (sm == null && !ImplHelper.isManagedType(getConfiguration(), entity.getClass())) throw new ArgumentException(_loc.get("not-entity", entity.getClass()), null, null, true); return sm != null && !sm.isDeleted(); }