Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

NET Framework Conceptual Overview




Компиляция кода

Пример

Перехват исключения

Compiling the Code

Example

Пример

class ProgramThrow{ static void DoWork(int x) { if (x > 5) { throw new System.ArgumentOutOfRangeException("X is too large"); } } static void Main() { try { DoWork(10); } catch (System.ArgumentOutOfRangeException ex) { System.Console.WriteLine(ex.Message); } }}

Если предполагается возникновение неожиданной ситуации, рекомендуется использовать исключения. Они будут полезны, например, при работе с данными, введенными пользователями, чтении файла или доступе к сведениям из Интернета.


How to: Catch an Exception

This example uses try-catch blocks to catch division by zero as an exception. After the exception is caught, the execution is resumed in the finally block.

int top = 0, bottom = 0, result = 0; try { result = top / bottom; } catch (System.Exception ex) { System.Console.WriteLine("{0} exception caught here.", ex.GetType().ToString()); System.Console.WriteLine(ex.Message); } finally { System.Console.WriteLine("Clean-up code executes here..."); } System.Console.WriteLine("Program execution continues here...");

//Oputput

System.DivideByZeroException exception caught here.

Attempted to divide by zero.

Clean-up code executes here...

Program execution continues here...

Copy the code and paste it into the Main method of a console application.


В этом примере используются блоки try-catch для выявления исключительной ситуации деления на ноль. После перехвата исключения выполнение продолжается в блоке finally.

int top = 0, bottom = 0, result = 0;   try { result = top / bottom; } catch (System.Exception ex) { System.Console.WriteLine("{0} exception caught here.", ex.GetType().ToString()); System.Console.WriteLine(ex.Message); } finally { System.Console.WriteLine("Clean-up code executes here..."); } System.Console.WriteLine("Program execution continues here...");

// Результат

System.DivideByZeroException exception caught here.

Attempted to divide by zero.

Clean-up code executes here...

Program execution continues here...

Скопируйте код и вставьте его в метод Main консольного приложения.


The.NET Framework is an integral Windows component that supports building and running the next generation of applications and XML Web services[ii]. The.NET Framework is designed to fulfill the following objectives:

· To provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.

· To provide a code-execution environment that minimizes software deployment and versioning conflicts.

· To provide a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party.

· To provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments.

· To make the developer experience consistent across widely varying types of applications, such as Windows-based applications and Web-based applications.

· To build all communication on industry standards to ensure that code based on the.NET Framework can integrate with any other code.

The.NET Framework has two main components: the common language runtime[iii] and the.NET Framework class library[iv]. The common language runtime is the foundation of the.NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code. The class library, the other main component of the.NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

The.NET Framework can be hosted by unmanaged components that load the common language runtime into their processes and initiate the execution of managed code, thereby creating a software environment that can exploit both managed and unmanaged features. The.NET Framework not only provides several runtime hosts, but also supports the development of third-party runtime hosts.





Поделиться с друзьями:


Дата добавления: 2014-12-27; Просмотров: 390; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.009 сек.