/
InvalidPrinterException.cs
43 lines (38 loc) · 1.25 KB
/
InvalidPrinterException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Security;
namespace System.Drawing.Printing;
/// <summary>
/// Represents the exception that is thrown when trying to access a printer using invalid printer settings.
/// </summary>
[Serializable]
public partial class InvalidPrinterException : SystemException
{
private readonly PrinterSettings? _settings;
/// <summary>
/// Initializes a new instance of the <see cref='InvalidPrinterException'/> class.
/// </summary>
public InvalidPrinterException(PrinterSettings settings)
: base(GenerateMessage(settings))
{
_settings = settings;
}
private static string GenerateMessage(PrinterSettings settings)
{
if (settings.IsDefaultPrinter)
{
return SR.InvalidPrinterException_NoDefaultPrinter;
}
else
{
try
{
return SR.Format(SR.InvalidPrinterException_InvalidPrinter, settings.PrinterName);
}
catch (SecurityException)
{
return SR.Format(SR.InvalidPrinterException_InvalidPrinter, SR.CantTellPrinterName);
}
}
}
}