This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void WithdrawMoney(decimal amount) | |
| { | |
| if (amount <= 0) | |
| { | |
| throw new ArgumentOutOfRangeException(nameof(amount), amount, "The amount to withdraw must be positive"); | |
| } | |
| // Actual withdraw code | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void WithdrawMoney(decimal amount) | |
| { | |
| if (amount <= 0) | |
| { | |
| throw new InvalidOperationException(); | |
| } | |
| // Actual withdraw code | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try | |
| { | |
| // Do something that might cause an exception | |
| } | |
| catch (IOException ex) | |
| { | |
| // Rethrow the exception without replacing its call stack | |
| throw; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (quantity <= 0) | |
| { | |
| throw new Exception("Quantity must be a positive number"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try | |
| { | |
| // Some code | |
| } | |
| catch | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try | |
| { | |
| // Some code | |
| } | |
| catch (Exception ex) | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int sum = 0; | |
| try | |
| { | |
| for (int i = 0; i <= myArray.Length; i++) | |
| { | |
| sum += myArray[i]; | |
| } | |
| } | |
| catch (IndexOutOfRangeException ex) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int FindLargestNumber(List<int> numbers) | |
| { | |
| int largest = int.MinValue; | |
| if (numbers != null) | |
| { | |
| foreach (int num in numbers) | |
| { | |
| if (largest < num) | |
| { | |
| largest = num; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try | |
| { | |
| string text = File.ReadAllText("MyFile.txt"); | |
| // Do something with text | |
| } | |
| catch (IOException ex) | |
| { | |
| // Display an error message | |
| } |
NewerOlder