Skip to content

Commit 77230ba

Browse files
committed
Throw better exception for invalid values. Fixes #763
1 parent f8c26b1 commit 77230ba

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnectionStringBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ public void SetValue(MySqlConnectionStringBuilder builder, T value) =>
678678

679679
public override object GetObject(MySqlConnectionStringBuilder builder) => GetValue(builder);
680680

681-
private static T ChangeType(object objectValue)
681+
private T ChangeType(object objectValue)
682682
{
683683
if (typeof(T) == typeof(bool) && objectValue is string booleanString)
684684
{
@@ -700,7 +700,14 @@ private static T ChangeType(object objectValue)
700700
}
701701
}
702702

703-
return (T) Convert.ChangeType(objectValue, typeof(T), CultureInfo.InvariantCulture);
703+
try
704+
{
705+
return (T) Convert.ChangeType(objectValue, typeof(T), CultureInfo.InvariantCulture);
706+
}
707+
catch (Exception ex)
708+
{
709+
throw new ArgumentException("Invalid value '{0}' for '{1}' connection string option.".FormatInvariant(objectValue, Key), ex);
710+
}
704711
}
705712

706713
readonly T m_defaultValue;

0 commit comments

Comments
 (0)