Reputation: 1050
I am getting the following compilation error in a .NET Core 1.0 class library:
“The type or namespace name ‘SystemException’ could not be found (are you missing a using directive or an assembly reference?)”, code: CS0246.
{
"name": "Dna.Net.Core",
"version": "1.0.0-*",
"dependencies": {
"Autofac": "4.1.0",
"NETStandard.Library": "1.6.0",
"System.Data.SqlClient": "4.1.0",
"System.Runtime": "4.1.0",
"System.Runtime.Serialization.Formatters": "4.0.0-rc3-24212-01",
"System.Runtime.Serialization.Primitives": "4.1.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
using Dna.Net.Core.Common;
using System;
namespace Dna.Net.Core.Exceptions
{
public partial interface ISystemExceptionMessageBuilder
{
CustomMessage Parse(SystemException ex);
}
}
The Framework Guideline states “DO NOT throw Exception or SystemException”.
A search within the coreFX project shows comments in classes that have refactored away from System.SystemException.
Can / will / should I be able to catch System.SystemException in .NET Core?
Upvotes: 3
Views: 2621
Reputation: 5270
System.SystemException
is not part of .NET Core (at least not netcoreapp1.0
or netstandard1.6
). However it seems scheduled for netcoreapp1.1
or netstandard1.7
.
The referenced source file of the other answer was probably not compiled into the System.Runtime
(or its companion System.Private.CoreLib
.
Answering your question: As of today you should not be able to catch System.SystemException
. For final handling you should catch System.Exception
and if you are able to handle the exception, it cannot be a System.SystemException
in .NET Core.
Upvotes: 3
Reputation: 531
System.SystemException exists in coreCLR - https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/SystemException.cs
So it is available in the mscorlib. So it can be used. But it is not recommended. As you will not get any specific information about the exception when you throw a system exception instead throw a relevant exception. System exception should be limited to system error (platform specific).
Upvotes: 0