- 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();
推薦閱讀
- 工程軟件開發技術基礎
- Java Web基礎與實例教程(第2版·微課版)
- Unity 2020 Mobile Game Development
- 程序員考試案例梳理、真題透解與強化訓練
- SSM輕量級框架應用實戰
- 琢石成器:Windows環境下32位匯編語言程序設計
- C語言程序設計上機指導與習題解答(第2版)
- C#程序設計(項目教學版)
- 微信小程序開發實戰:設計·運營·變現(圖解案例版)
- Data Science Algorithms in a Week
- Qt 4開發實踐
- Appcelerator Titanium:Patterns and Best Practices
- Python預測之美:數據分析與算法實戰(雙色)
- 走近SDN/NFV
- TensorFlow 2.0深度學習應用實踐