- 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();
推薦閱讀
- Python量化投資指南:基礎(chǔ)、數(shù)據(jù)與實戰(zhàn)
- PostgreSQL for Data Architects
- Java面向?qū)ο笏枷肱c程序設(shè)計
- Python for Secret Agents:Volume II
- Bulma必知必會
- Practical Windows Forensics
- 游戲程序設(shè)計教程
- Nginx實戰(zhàn):基于Lua語言的配置、開發(fā)與架構(gòu)詳解
- Visual Basic程序設(shè)計實踐教程
- Java Web開發(fā)詳解
- C#開發(fā)案例精粹
- Hands-On Kubernetes on Windows
- Java高并發(fā)編程詳解:深入理解并發(fā)核心庫
- Processing開發(fā)實戰(zhàn)
- C語言從入門到精通(視頻實戰(zhàn)版)