File

projects/wms-framework/src/lib/baseframework/Exceptions.ts

Description

Implementation of the Exception type, it implements Error type to offer compatibility with standard javascript code, migrated code will tend to throw exceptions extending from Exception, but third-party libraries or even angular code might assume what was thrown was an Error and try to get default properties like name, message or stack

Implements

Error

Index

Properties
Methods
Accessors

Constructor

constructor(description?: string, innerException?: Exception)
Parameters :
Name Type Optional
description string Yes
innerException Exception Yes

Properties

description
Type : string
Default value : ''
innerError
Type : Error
InnerException
Type : Exception
Default value : null

Methods

Public GetType
GetType()

Gets the type of the exception

Returns : any

Accessors

name
getname()

Implementation for Error.name for compatibility

Returns : string
message
getmessage()

Implementation for Error.message for compatibility

Returns : string
stack
getstack()

Implementation for Error.stack for compatibility

Returns : string
Message
getMessage()
StackTrace
getStackTrace()
import { Debugger } from '../diagnostics/Debugger';

/**
 * Implementation of the Exception type, it implements Error type to offer compatibility with standard javascript code,
 * migrated code will tend to throw exceptions extending from Exception, but third-party libraries or even angular code
 * might assume what was thrown was an Error and try to get default properties like name, message or stack
 *
 * @export
 * @class Exception
 * @implements {Error}
 * @wType System.Exception
 * @wNetSupport
 */
export class Exception implements Error {
  /**
   * Implementation for Error.name for compatibility
   *
   * @readonly
   * @type {string}
   * @memberof Exception
   */
  get name(): string {
    return typeof this;
  }

  /**
   * Implementation for Error.message for compatibility
   *
   * @readonly
   * @type {string}
   * @memberof Exception
   */
  get message(): string {
    return this.Message;
  }

  /**
   * Implementation for Error.stack for compatibility
   *
   * @readonly
   * @type {string}
   * @memberof Exception
   */
  get stack(): string {
    return this.StackTrace;
  }

  innerError: Error;
  InnerException: Exception = null;
  description: string = '';

  public get Message(): string {
    return this.description;
  }

  constructor();
  constructor(description: string);
  constructor(description: string, innerException: Exception);
  constructor(description?: string, innerException?: Exception) {
    this.innerError = new Error();
    this.InnerException = innerException;
    this.description = description;
  }

  get StackTrace(): string {
    return this.innerError.stack || '';
  }

  /**
   * Gets the type of the exception
   *
   * @returns {*}
   * @memberof Exception
   * @wNoMap
   */
  public GetType(): any {
    Debugger.Throw('Not implemented');
  }
}

/**
 * Tries to generate an Exception object out of the 'e' parameter, parameter
 * might be an Exception so it will be returned or most likely might be an Error
 * type, in such case it will create a new Exception containing e as innerError
 *
 * @export
 * @param {*} e
 * @return {*}  {Exception}
 */
export function smGetExceptionInstance(e: any): Exception {
  if (e == null) return null;

  if (e instanceof Exception) {
    return e;
  } else {
    const msg: string = e?.message ?? 'Unknown Exception';
    const ex: Exception = new Exception(msg);
    ex.innerError = e;

    return ex;
  }
}

/**
 *  Exception for argument errors
 *
 * @export
 * @class ArgumentException
 * @extends {Exception}
 * @wType System.ArgumentException
 * @wNetSupport
 */
export class ArgumentException extends Exception {
  /**
   * Creates an instance of ArgumentException.
   * @memberof ArgumentException
   */
  constructor();
  constructor(message: string);
  constructor(message: string, argumentName: string);
  constructor(message: string, exception: Exception);
  constructor(p1?, p2?) {
    super(p1 ?? '', p2 instanceof Exception ? p2 : null);
  }
}

/**
 * Argument null exception
 *
 * @export
 * @class ArgumentNullException
 * @wType System.ArgumentNullException
 * @wNetSupport
 */
export class ArgumentNullException {
  constructor(argumentName: string, description?: string) {}
}

/**
 * Not implemented exception class.
 *
 * @export
 * @class NotImplementedException
 * @wType System.NotImplementedException
 * @wNetSupport
 */
export class NotImplementedException {
  constructor(description?: string) {}
}

/**
 * StackFrame class.
 *
 * @export
 * @class StackFrame
 * @wType System.Diagnostics.StackFrame
 * @wNetSupport
 */
export class StackFrame {
  /**
   * Gets method associated to stackframe
   *
   * @returns {*}
   * @memberof StackFrame
   * @wNoMap
   */
  public GetMethod(): any {
    Debugger.Throw('Not implemented');
  }
}

/**
 * StackTrace class.
 *
 * @export
 * @class StackTrace
 * @wType System.Diagnostics.StackTrace
 * @wNetSupport
 */
export class StackTrace {
  constructor(exception?: any) {}

  /**
   * Gets frame
   *
   * @param {number} [n]
   * @returns {StackFrame}
   * @memberof StackTrace
   * @wNoMap
   */
  public GetFrame(n?: number): StackFrame {
    Debugger.Throw('Not implemented');
    return null;
  }
}

/**
 * Invalid operation exception
 *
 * @export
 * @class InvalidOperationException
 * @extends {Exception}
 * @wType System.InvalidOperationException
 * @wNetSupport
 */
export class InvalidOperationException extends Exception {
  constructor(description: string) {
    super(description);
  }
}

/**
 * Not supported exception
 *
 * @export
 * @class NotSupportedException
 * @extends {Exception}
 * @wType System.NotSupportedException
 * @wNetSupport
 */
export class NotSupportedException extends Exception {
  constructor(description?: string) {
    super(description || '');
  }
}

/**
 * Communication exception.
 *
 * @export
 * @class CommunicationException
 * @extends {Exception}
 * @wType System.ServiceModel.CommunicationException
 */
export class CommunicationException extends Exception {
  /**
   * Creates an instance of ComunicationException.
   * @memberof ComunicationException
   */
  constructor();
  constructor(message: string);
  constructor(message: string, innerException: Exception);
  constructor(p1?, p2?) {
    super(p1 ?? '', p2 instanceof Exception ? p2 : null);
  }
}

/**
 *  Exception for Soap faults
 *
 * @export
 * @class FaultException
 * @extends {Exception}
 * @wType System.ServiceModel.FaultException`1
 */
export class FaultException<TDetail> extends CommunicationException {
  /**
   * Object that contains the detail information of the fault condition
   */
  Detail: TDetail;

  /**
   * Creates an instance of FaultException.
   * @memberof FaultException
   */
  constructor();
  constructor(message: string);
  constructor(message: string, innerException: Exception);
  constructor(p1?, p2?) {
    super(p1 ?? '', p2 instanceof Exception ? p2 : null);
  }
}

/**
 *  Exception for invalid format of an argument
 *
 * @export
 * @class FormatException
 * @extends {Exception}
 * @wType System.FormatException
 * @wNetSupport
 */
export class FormatException extends Exception {
  /**
   * Creates an instance of FormatException.
   * @memberof FormatException
   */
  constructor();
  constructor(message: string);
  constructor(message: string, innerException: Exception);
  constructor(p1?, p2?) {
    super(p1 ?? '', p2 instanceof Exception ? p2 : null);
  }
}

result-matching ""

    No results matching ""