当前位置:网站首页>C program debugging and exception handling (try catch)
C program debugging and exception handling (try catch)
2022-07-27 12:34:00 【InfoQ】
Preface :
Once a day , Study makes me progress

1. Program debugging
1.1 Common mistakes



1.2. Debugging method

2. Exception capture and handling
// Concept
try: One try Block identifies a block of code for a specific exception that will be activated . One or more heels catch block .
catch: The program catches the exception through the exception handler .catch The keyword represents the capture of an exception .
finally:finally Block is used to execute a given statement , The exception is executed whether it is thrown or not . for example , If you open a file , No matter whether there is an exception or not, the file will be closed .
throw: When problems arise , The program throws an exception . Use throw Keyword to complete .
// usage
try ... catch{// Exception handling code } // Capture exception , Can be more catch
try ... finally{ // Used to eliminate try Any resources allocated in the block and Run any code that must be executed even when an exception occurs } // Clear exceptions
try ... catch ... finally // Handle all exceptions , The combination of the first two
// You need to throw an object
If the exception is derived directly or indirectly from System.Exception class , You can throw an object . You can go to catch Block the use of throw Statement to throw the current object , As shown below :
Catch(Exception e)
{
...
Throw e
}

2.1 Exception classes understand
// Common exception classes
Exception: Base class for all exception objects .
SystemException: Base class for all errors generated at runtime .
IndexOutOfRangeException: When the subscript of an array is out of range, the runtime raises .
NullReferenceException: Raised by the runtime when an empty object is referenced .
InvalidOperationException: When the call to a method is invalid for the current state of the object , Caused by certain methods .
ArgumentException: Base class for all parameter exceptions .
ArgumentNullException: When the parameter is empty ( Don't allow ) Under the circumstances , Raised by method .
ArgumentOutOfRangeException: When the parameter is not within a given range , Raised by method .
InteropException: The goal is or occurs in CLR The base class of exceptions in the external environment .
ComException: contain COM Class HRESULT Abnormal information .
SEHException: encapsulation Win32 Structural exception handling information exception .
SqlException: Encapsulates the SQL Abnormal operation .
// other Exception Class description
SystemException Basic classes of exceptions that other users can handle
ArgumentException Method parameters are illegal
ArgumentNullException An empty parameter is passed to the method , This method cannot accept this parameter
ArgumentOutOfRangeException Parameter value is out of range
ArithmeticException Arithmetic overflow or underflow occurs
ArrayTypeMismatchException Trying to store an object of the wrong type in an array
BadImageFormatException The graphics are in the wrong format
DivideByZeroException Abnormal division by zero
DllNotFoundException The referenced DLL
FormatException Parameter format error
IndexOutOfRangeException Array index out of range
InvalidCastException Use invalid class
InvalidOperationException Method call time error
MethodAccessException Try to visit Siyou or protected methods
MissingMemberException Access an invalid version of DLL
NotFiniteNumberException Object is not a valid member
NotSupportedException The method called is not implemented in the class
NullReferenceException Trying to use an unassigned reference
OutOfMemoryException Not enough memory
PlatformNotSupportedException This error is thrown when the platform does not support a specific property
StackOverflowException stack overflow
Exception: Base class for all exception objects .
SystemException: Base class for all errors generated at runtime .
IndexOutOfRangeException: When the subscript of an array is out of range, the runtime raises .
NullReferenceException: Raised by the runtime when an empty object is referenced .
InvalidOperationException: When the call to a method is invalid for the current state of the object , Caused by certain methods .
ArgumentException: Base class for all parameter exceptions .
ArgumentNullException: When the parameter is empty ( Don't allow ) Under the circumstances , Raised by method .
ArgumentOutOfRangeException: When the parameter is not within a given range , Raised by method .
InteropException: The goal is or occurs in CLR The base class of exceptions in the external environment .
ComException: contain COM Class HRESULT Abnormal information .
SEHException: encapsulation Win32 Structural exception handling information exception .
SqlException: Encapsulates the SQL Abnormal operation .
2.2 Custom exception

class outException : ApplicationException// Our custom exception class inherits Exception The derived class ApplicationException To complete
{
string str;
public outException():base()// Define the constructor
{
this.str = " We don't accept 1 This number is the divisor ,IC00 Yes !";
}
public override string ToString()// Rewrite Tostring
{
return str.ToString();
}
}
summary

边栏推荐
- Solution: the idea project does not display a tree view
- Interviewer: how can you close an order without using a scheduled task?
- Go Beginner (3)
- V. introduction of other objectives and general options
- Go Introduction (2)
- One article to understand the index of like in MySQL
- Lonely young people can't quit jellycat
- Unity 2D game tutorial
- Kazoo tutorial
- Bishi journey
猜你喜欢

详述try-catch-finally

J9 number theory: how long is the mainstreaming of decentralized identity?

Implicit indicators for evaluating the advantages and disadvantages of automated testing

Set接口

How to use the server to build our blog

20210419 combined sum

Basic architecture of data Lake
Ali II: what if the AOF file in redis is too large?

Configuration files in MySQL

Photoshop web design tutorial
随机推荐
Chapter 7 exception handling
MySQL common commands
Log4j2.xml configuration details
为什么需要外键?
@Postconstruct annotations and initializingbean perform some initialization operations after bean instantiation
Binary search decision tree (average search length of binary search tree)
Switching value input and output module dam-5055
Lambda 表达式
[product] about wechat product analysis
What should I do if I can't see any tiles on SAP Fiori launchpad?
While loop instance in shell
The configuration change removed the routing filter, and the distributed router was overwhelmed: the Canadian network was paralyzed
20210422 consolidation interval
2021-3-17-byte-hu Pai
After Party A's hard work, 49.08 million orders of China Mobile were scrapped
详述HashSet的add方法
Chapter 8 multithreading
评价自动化测试优劣的隐性指标
HDU1698_ Just a Hook
事务四大特性(ACID):