- Mastering Visual Studio 2017
- Kunal Chowdhury
- 123字
- 2021-07-15 17:26:39
Changes to the throw expression
The earlier versions of C# had some limitations on throwing exceptions from certain places, which caused developers to write more code to validate and raise exceptions. In C# 7.0, those limitations have been removed to reduce the overload.
The Null Coalescing operator now allows you to throw an exception in the middle of the expression without explicitly checking for null:
m_designation = designation ?? throw new ArgumentNullException(designation);
It is now possible to throw an exception from the Conditional operator too:
m_department = department == null ? throw new ArgumentNullException(department) : department;
C# 7.0 also allows you to throw an exception from expression-bodied member, as shown in the following code snippet:
public void SetSalary(double salary) => throw new NotImplementedException();
推薦閱讀
- Debian 7:System Administration Best Practices
- Machine Learning with R Cookbook(Second Edition)
- Python網(wǎng)絡(luò)爬蟲從入門到實(shí)踐(第2版)
- Mastering Articulate Storyline
- C#程序設(shè)計(jì)
- Python機(jī)器學(xué)習(xí)算法與實(shí)戰(zhàn)
- RabbitMQ Essentials
- HTML5從入門到精通(第4版)
- Mastering Python Design Patterns
- Python趣味編程與精彩實(shí)例
- Learning iOS Security
- Visual C++開發(fā)寶典
- After Effects CC案例設(shè)計(jì)與經(jīng)典插件(視頻教學(xué)版)
- Mastering Leap Motion
- 基于MATLAB的控制系統(tǒng)仿真及應(yīng)用