public void WithdrawMoney(int amount) { if (amount > Balance) { throw new InsufficientBalanceException("Insufficient balance in the account."); } else { Balance -= amount; } }
public void ReadFile(string filename) { try { // Method code to open and read the file } catch(FileNotFoundException ex) { throw new FileLoadException("File not found error occurred.", ex); } catch(IOException ex) { throw new FileLoadException("IO error occurred while reading the file.", ex); } }In this example, the method ReadFile() is declared to throw a FileLoadException if an exception of type FileNotFoundException or IOException occurs. It also provides information about the error that occurred. The Throws InstanceOf feature is part of the System namespace in the .NET Framework.