LinePrinter Tutorial > Part 3 of 6

Part 3: Add a function to display errors

  1. Add this code:
static public void ShowError(Exception e)
{
    string Message = "UNKNOWN ERROR WHILE PRINTING";
    if (e is LinePrinterException)
    {
        LinePrinterException lpe = (LinePrinterException)e;
        if (lpe.ErrorType == LinePrinterException.ErrorTypes.CONFIG_ERROR)
        {
            Message =
            "PRINTER CONFIGURATION ERROR\r\n\r\nPossibly invalid configuration file!";
        }
        else if (lpe.ErrorType == LinePrinterException.ErrorTypes.PRINTER_ERROR)
        {
            Message = string.Format(
                "PRINTER ERROR\n\r\n\rError # {0} - {1}",
                lpe.ErrorCode,GetErrorStr(lpe.ErrorCode));
        }
    }
    MessageBox.Show(Message,
        "REPORT ERROR!",
        MessageBoxButtons.OK,MessageBoxIcon.Exclamation,
        MessageBoxDefaultButton.Button1);
}
  1. Add a reference to System.Windows.Forms.
  2. Add a "using System.Windows.Forms" statement so the application can use a MessageBox.

Next » Tutorial Part 4

Back « Tutorial Part 2