Academic Tutorials



English | French | Portugese | Dutch | Italian
Google

em linha

Home Códigos de fonte E-Livros Downloads Contatar-nos Sobre nós

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting


Manipulação de exceção


Previous Next





Manipulação de exceção

Praticamente todo o programa including o c# .net pode ter alguma quantidade de erros. Podem amplamente ser classificados como erros compile-time e erros runtime. Os erros Compile-time são os erros que podem ser encontrados durante o processo da compilação do código de fonte. A maioria deles são erros da sintaxe. Os erros Runtime acontecem quando o programa está funcionando.

É muito difícil de encontrar e eliminar erros dos erros run-time. Estes erros chamaram também exceções. As réguas do estilo bom do coding dizem que o programa deve segura todo o erro runtime. A exceção gera uma chamada da exceção no runtime. As exceções em C# podem ser chamadas usando dois métodos:

  • Usando o operador do throw. Chama o código controlar de qualquer maneira e processa uma exceção.
  • Se usar os operadores for awry, pode gerar uma exceção.




Tipos diferentes de exceções

A língua de C# usa muitos tipos de exceções, que são definidas em classes especiais. Todo são herdadas da classe baixa nomeada System.Exception. Há as classes que processam muitos tipos das exceções: fora da exceção da memória, a exceção do excesso de pilha, exceção nula da referência, índice fora da exceção da escala, invalid moldou a exceção, a exceção aritmética etc. Este tutorial do c# trata das classes da exceção e do costume do c# de DivideByZero em exceções do c#.

C# definiu alguns keywords para processar exceções. O mais importantes são tentativa, prendedor e finalmente.

Primeiro a ser sabido é o operador da tentativa. Isto é usado em uma parte do código, onde existe uma possibilidade de exceção a ser jogada. Mas operador? tentativa? é usado sempre com os operadores: prendedor e finalmente.

Ver o seguinte exemplo de segurar uma exceção simples no c#.

// try catch exception
int zero = 0;
try
{
int div = 100/zero;
}
catch(DivideByZeroException)
{
Console.WriteLine("Division by zero exception passed");
}

Este código no runtime joga um DivideByZeroException e escreve alguma mensagem através do console. Mas se você quiser se liberar alguns recursos que lhe foram criados devem usar a tentativa? finalmente construção. Será chamado finalmente mesmo se não houver nenhuma exceção levantada.

Bitmap bit = null;
// try finally exception
try
{
bit = new Bitmap(100,100);
}
finally
{
bit.Dispose();
Console.WriteLine("bitmap is disposed");
}

Na maneira similar nós podemos usar a tentativa? prendedor? finalmente construção.

Alguns projetos maiores puderam ter uma exigência de criar suas próprias classes feitas sob encomenda da exceção. Deixar-nos tentar criar a classe que valida o email address. Validará para? @? símbolo. Ter por favor um olhar na seguinte parte de código:

public class TextException : Exception
{
public TextException() : base()
{
}

public TextException(string message) : base(message)
{
}
}

public class MailValidator
{
MailValidator()
{
}

private static char symbol = '@';

public static void TestEnteredMail(string mailAddress)
{
if(mailAddress.IndexOf(symbol)==-1)
{
Console.WriteLine("The string entered is not a valid email address");
throw(new TextException());
}
}
}

Foram criados aqui A.A. #. Classe líquida de TextException que herda da classe de System.Exception da biblioteca da classe de .NET. Realmente não faz nada, mas há uma classe adicional MailValidator. Tem o método de TestEnteredMail que levanta um TextException. Olhar agora o uso dele na função principal.

try
{
MailValidator.TestEnteredMail(Console.ReadLine());
}
catch(TextException)
{
Console.WriteLine("Exception was passed");
}

Assim, se o usuário incorporar o endereço do correio sem “@” throws do símbolo uma exceção.





Previous Next

Keywords Exception Handling, java exception, oracle exception, c++ exception, c# exception, jsp exception, exception api, exception tutorial, throw exception, exception framework, exception vc++, exception plsql, struts exception, exception throwing, package handling, throws exception, exception servlet, exception sql, sample handling, exception block, catch exception, application exception, exception method


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizes
Oracle Quiz
MySQL Quiz
Operating System Quizes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizes
Testing Quiz
Firewalls Quiz
SAP Module Quizes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizes
Corba Quiz
Networking Quiz
Microsoft Office Quizes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizes
Financial Accounting Quiz
Managerial Accounting Quiz

Privacy Policy
Copyright © 2003-2025 Vyom Technosoft Pvt. Ltd., All Rights Reserved.