├── ByteBank ├── App.config ├── Cliente.cs ├── OperacaoFinanceiraException.cs ├── LeitorDeArquvos.cs ├── SaldoInsuficienteException.cs ├── Properties │ └── AssemblyInfo.cs ├── ByteBank.csproj ├── ContaCorrente.cs └── Program.cs └── ByteBank.sln /ByteBank/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ByteBank/Cliente.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ByteBank 8 | { 9 | public class Cliente 10 | { 11 | public string Nome { get; set; } 12 | public string CPF { get; set; } 13 | public string Profissao { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ByteBank/OperacaoFinanceiraException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ByteBank 8 | { 9 | public class OperacaoFinanceiraException : Exception 10 | { 11 | public OperacaoFinanceiraException() 12 | { 13 | 14 | } 15 | 16 | public OperacaoFinanceiraException(string mensagem) 17 | : base(mensagem) 18 | { 19 | 20 | } 21 | 22 | public OperacaoFinanceiraException(string mensagem, Exception excecaoInterna) 23 | : base(mensagem, excecaoInterna) 24 | { 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ByteBank/LeitorDeArquvos.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ByteBank 9 | { 10 | public class LeitorDeArquivo : IDisposable 11 | { 12 | public string Arquivo { get; } 13 | 14 | public LeitorDeArquivo(string arquivo) 15 | { 16 | Arquivo = arquivo; 17 | 18 | // throw new FileNotFoundException(); 19 | 20 | Console.WriteLine("Abrindo arquivo: " + arquivo); 21 | } 22 | 23 | public string LerProximaLinha() 24 | { 25 | Console.WriteLine("Lendo linha. . ."); 26 | 27 | throw new IOException(); 28 | 29 | return "Linha do arquivo"; 30 | } 31 | 32 | public void Dispose() 33 | { 34 | Console.WriteLine("Fechando arquivo."); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ByteBank/SaldoInsuficienteException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ByteBank 8 | { 9 | public class SaldoInsuficienteException : OperacaoFinanceiraException 10 | { 11 | public double Saldo { get; } 12 | public double ValorSaque { get; } 13 | 14 | public SaldoInsuficienteException() 15 | { 16 | 17 | } 18 | 19 | public SaldoInsuficienteException(double saldo, double valorSaque) 20 | : this("Tentativa de saque do valor de " + valorSaque + " em uma conta com saldo de " + saldo) 21 | { 22 | Saldo = saldo; 23 | ValorSaque = valorSaque; 24 | } 25 | 26 | public SaldoInsuficienteException(string mensagem) 27 | : base(mensagem) 28 | { 29 | } 30 | 31 | public SaldoInsuficienteException(string mensagem, Exception excecaoInterna) 32 | : base(mensagem, excecaoInterna) 33 | { 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ByteBank.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2027 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteBank", "ByteBank\ByteBank.csproj", "{D5B03F93-CDC4-4309-AE8E-FFD218108A1A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D5B03F93-CDC4-4309-AE8E-FFD218108A1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D5B03F93-CDC4-4309-AE8E-FFD218108A1A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D5B03F93-CDC4-4309-AE8E-FFD218108A1A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D5B03F93-CDC4-4309-AE8E-FFD218108A1A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1C45512E-F3D6-4FDB-B508-BFF86AE9B109} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ByteBank/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // As informações gerais sobre um assembly são controladas por 6 | // conjunto de atributos. Altere estes valores de atributo para modificar as informações 7 | // associada a um assembly. 8 | [assembly: AssemblyTitle("ByteBank")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ByteBank")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Definir ComVisible como false torna os tipos neste assembly invisíveis 18 | // para componentes COM. Caso precise acessar um tipo neste assembly de 19 | // COM, defina o atributo ComVisible como true nesse tipo. 20 | [assembly: ComVisible(false)] 21 | 22 | // O GUID a seguir será destinado à ID de typelib se este projeto for exposto para COM 23 | [assembly: Guid("d5b03f93-cdc4-4309-ae8e-ffd218108a1a")] 24 | 25 | // As informações da versão de um assembly consistem nos quatro valores a seguir: 26 | // 27 | // Versão Principal 28 | // Versão Secundária 29 | // Número da Versão 30 | // Revisão 31 | // 32 | // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão 33 | // utilizando o "*" como mostrado abaixo: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ByteBank/ByteBank.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D5B03F93-CDC4-4309-AE8E-FFD218108A1A} 8 | Exe 9 | ByteBank 10 | ByteBank 11 | v4.6.1 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /ByteBank/ContaCorrente.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ByteBank 8 | { 9 | public class ContaCorrente 10 | { 11 | private static int TaxaOperacao; 12 | 13 | public static int TotalDeContasCriadas { get; private set; } 14 | 15 | public Cliente Titular { get; set; } 16 | 17 | public int ContadorSaquesNaoPermitidos { get; private set; } 18 | public int ContadorTransferenciasNaoPermitidas { get; private set; } 19 | 20 | public int Numero { get; } 21 | public int Agencia { get; } 22 | 23 | private double _saldo = 100; 24 | public double Saldo 25 | { 26 | get 27 | { 28 | return _saldo; 29 | } 30 | set 31 | { 32 | if (value < 0) 33 | { 34 | return; 35 | } 36 | 37 | _saldo = value; 38 | } 39 | } 40 | 41 | public ContaCorrente(int agencia, int numero) 42 | { 43 | if (numero <= 0) 44 | { 45 | throw new ArgumentException("O argumento agencia deve ser maior que 0.", nameof(agencia)); 46 | } 47 | 48 | if(numero <= 0) 49 | { 50 | throw new ArgumentException("O argumento numero deve ser maior que 0.", nameof(numero)); 51 | } 52 | 53 | Agencia = agencia; 54 | Numero = numero; 55 | 56 | TotalDeContasCriadas++; 57 | TaxaOperacao = 30 / TotalDeContasCriadas; 58 | } 59 | 60 | public void Sacar(double valor) 61 | { 62 | if (valor < 0) 63 | { 64 | throw new ArgumentException("Valor inválido para o saque.", nameof(valor)); 65 | } 66 | 67 | if (_saldo < valor) 68 | { 69 | ContadorSaquesNaoPermitidos++; 70 | throw new SaldoInsuficienteException(Saldo, valor); 71 | } 72 | 73 | _saldo -= valor; 74 | } 75 | 76 | public void Depositar(double valor) 77 | { 78 | _saldo += valor; 79 | } 80 | 81 | public void Transferir(double valor, ContaCorrente contaDestino) 82 | { 83 | if (valor < 0) 84 | { 85 | throw new ArgumentException("Valor inválido para a transferência.", nameof(valor)); 86 | } 87 | 88 | try 89 | { 90 | Sacar(valor); 91 | } 92 | catch(SaldoInsuficienteException ex) 93 | { 94 | ContadorTransferenciasNaoPermitidas++; 95 | throw new OperacaoFinanceiraException("Operação não realizada.", ex); 96 | } 97 | 98 | contaDestino.Depositar(valor); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ByteBank/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ByteBank 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | try 15 | { 16 | CarregarContas(); 17 | } 18 | catch(Exception) 19 | { 20 | Console.WriteLine("CATCH NO METODO MAIN"); 21 | } 22 | 23 | Console.WriteLine("Execução finalizada. Tecle enter para sair"); 24 | Console.ReadLine(); 25 | } 26 | 27 | private static void CarregarContas() 28 | { 29 | using (LeitorDeArquivo leitor = new LeitorDeArquivo("teste.txt")) 30 | { 31 | leitor.LerProximaLinha(); 32 | } 33 | 34 | 35 | 36 | // --------------------------------------------- 37 | 38 | //LeitorDeArquivo leitor = null; 39 | //try 40 | //{ 41 | // leitor = new LeitorDeArquivo("contasl.txt"); 42 | 43 | // leitor.LerProximaLinha(); 44 | // leitor.LerProximaLinha(); 45 | // leitor.LerProximaLinha(); 46 | //} 47 | //finally 48 | //{ 49 | // Console.WriteLine("Executando o finally"); 50 | // if(leitor != null) 51 | // { 52 | // leitor.Fechar(); 53 | // } 54 | //} 55 | } 56 | 57 | private static void TestaInnerException() 58 | { 59 | try 60 | { 61 | ContaCorrente conta1 = new ContaCorrente(4564, 789684); 62 | ContaCorrente conta2 = new ContaCorrente(7891, 456794); 63 | 64 | // conta1.Transferir(10000, conta2); 65 | conta1.Sacar(10000); 66 | } 67 | catch (OperacaoFinanceiraException e) 68 | { 69 | Console.WriteLine(e.Message); 70 | Console.WriteLine(e.StackTrace); 71 | 72 | // Console.WriteLine("Informações da INNER EXCEPTION (exceção interna):"); 73 | 74 | } 75 | } 76 | 77 | // Teste com a cadeia de chamada: 78 | // Metodo -> TestaDivisao -> Dividir 79 | private static void Metodo() 80 | { 81 | TestaDivisao(0); 82 | } 83 | 84 | private static void TestaDivisao(int divisor) 85 | { 86 | int resultado = Dividir(10, divisor); 87 | Console.WriteLine("Resultado da divisão de 10 por " + divisor + " é " + resultado); 88 | } 89 | 90 | private static int Dividir(int numero, int divisor) 91 | { 92 | try 93 | { 94 | return numero / divisor; 95 | } 96 | catch (DivideByZeroException ) 97 | { 98 | Console.WriteLine("Exceção com numero=" + numero + " e divisor=" + divisor); 99 | throw; 100 | Console.WriteLine("Código depois do throw"); 101 | } 102 | } 103 | 104 | // numero = 1 105 | // divisor = 2; 106 | 107 | } 108 | } 109 | --------------------------------------------------------------------------------