Skip to content

Instantly share code, notes, and snippets.

View IntegerMan's full-sized avatar
👨‍🔬
Writing "Data Science in .NET with Polyglot Notebooks"

Matt Eland IntegerMan

👨‍🔬
Writing "Data Science in .NET with Polyglot Notebooks"
View GitHub Profile
public void WithdrawMoney(decimal amount)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), amount, "The amount to withdraw must be positive");
}
// Actual withdraw code
}
public void WithdrawMoney(decimal amount)
{
if (amount <= 0)
{
throw new InvalidOperationException();
}
// Actual withdraw code
}
try
{
// Do something that might cause an exception
}
catch (IOException ex)
{
// Rethrow the exception without replacing its call stack
throw;
}
try
{
// Do something that might cause an exception
}
catch (IOException ex)
{
// We decide we don't really want to handle this exception
// Let's re-throw it so calling methods can catch it
throw ex;
}
if (quantity <= 0)
{
throw new Exception("Quantity must be a positive number");
}
try
{
// Some code
}
catch
{
}
try
{
// Some code
}
catch (Exception ex)
{
}
int sum = 0;
try
{
for (int i = 0; i <= myArray.Length; i++)
{
sum += myArray[i];
}
}
catch (IndexOutOfRangeException ex)
{
public int FindLargestNumber(List<int> numbers)
{
int largest = int.MinValue;
if (numbers != null)
{
foreach (int num in numbers)
{
if (largest < num)
{
largest = num;
try
{
string text = File.ReadAllText("MyFile.txt");
// Do something with text
}
catch (IOException ex)
{
// Display an error message
}