Skip to content

Commit

Permalink
Follow MS guidelines for custom exception types.
Browse files Browse the repository at this point in the history
- make custom exception types serializable.
  • Loading branch information
xprl-gjf authored and mrbean-bremen committed Dec 29, 2023
1 parent ef55e3c commit bf89bf4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
49 changes: 30 additions & 19 deletions Source/Exceptions/SvgException.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Svg
{
[Serializable]
public class SvgException : FormatException
{
public SvgException(string message) : base(message)
{
}
public SvgException() { }
public SvgException(string message) : base(message) { }
public SvgException(string message, Exception inner) : base(message, inner) { }

protected SvgException(SerializationInfo info, StreamingContext context)
: base (info, context) { }
}

[Serializable]
public class SvgIDException : FormatException
{
public SvgIDException(string message)
: base(message)
{
}
public SvgIDException() { }
public SvgIDException(string message) : base(message) { }
public SvgIDException(string message, Exception inner) : base(message, inner) { }

protected SvgIDException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

[Serializable]
public class SvgIDExistsException : SvgIDException
{
public SvgIDExistsException(string message)
: base(message)
{
}
public SvgIDExistsException() { }
public SvgIDExistsException(string message) : base(message) { }
public SvgIDExistsException(string message, Exception inner) : base(message, inner) { }

private SvgIDExistsException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

[Serializable]
public class SvgIDWrongFormatException : SvgIDException
{
public SvgIDWrongFormatException(string message)
: base(message)
{
}
public SvgIDWrongFormatException() { }
public SvgIDWrongFormatException(string message) : base(message) { }
public SvgIDWrongFormatException(string message, Exception inner) : base(message, inner) { }

private SvgIDWrongFormatException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
}
19 changes: 15 additions & 4 deletions Source/Exceptions/SvgGdiPlusCannotBeLoadedException.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
using System;
using System;
using System.Runtime.Serialization;

namespace Svg
{
public class SvgGdiPlusCannotBeLoadedException : Exception
[Serializable]
public sealed class SvgGdiPlusCannotBeLoadedException : Exception
{
public SvgGdiPlusCannotBeLoadedException(Exception inner) : base("Cannot initialize gdi+ libraries. This is likely to be caused by running on a non-Windows OS without proper gdi+ replacement. Please refer to the documentation for more details.", inner) {}
const string gdiErrorMsg = "Cannot initialize gdi+ libraries. This is likely to be caused by running on a non-Windows OS without proper gdi+ replacement. Please refer to the documentation for more details.";

public SvgGdiPlusCannotBeLoadedException() : base(gdiErrorMsg) { }
public SvgGdiPlusCannotBeLoadedException(string message) : base(message) { }
public SvgGdiPlusCannotBeLoadedException(Exception inner) : base(gdiErrorMsg, inner) {}
public SvgGdiPlusCannotBeLoadedException(string message, Exception inner) : base(message, inner) { }

private SvgGdiPlusCannotBeLoadedException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
}
10 changes: 3 additions & 7 deletions Source/Exceptions/SvgMemoryException.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Svg.Exceptions
{
[Serializable]
public class SvgMemoryException : Exception
public sealed class SvgMemoryException : Exception
{
public SvgMemoryException() { }
public SvgMemoryException(string message) : base(message) { }
public SvgMemoryException(string message, Exception inner) : base(message, inner) { }

protected SvgMemoryException(
SerializationInfo info,
StreamingContext context) : base(info, context) { }
private SvgMemoryException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
3 changes: 3 additions & 0 deletions doc/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ The release versions are NuGet releases.

## Unreleased (master)

### Enhancements
* made exceptions serializable to be able to cross AppDomain boundaries (see [#826](https://github.com/svg-net/SVG/pull/826))

### Fixes
* fixed filled polyline not displayed with stroke-width=0 (see [#785](https://github.com/svg-net/SVG/issues/785)
* fixed unimplemented filter classes issue (see [#768](https://github.com/svg-net/SVG/issues/768)
Expand Down

0 comments on commit bf89bf4

Please sign in to comment.