Class GError

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class GError extends ProxyInstance
The GError structure contains information about an error that has occurred.
  • Constructor Details

    • GError

      public GError(MemorySegment address)
      Create a GError proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • GError

      public GError(Quark domain, int code, String format, Object... varargs)
      Creates a new GError with the given domain and code, and a message formatted with format.
      Parameters:
      domain - error domain
      code - error code
      format - printf()-style format for error message
      varargs - parameters for message format
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the GError class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readDomain

      public Quark readDomain()
      Read the value of the field domain.
      Returns:
      The value of the field domain
    • writeDomain

      public void writeDomain(Quark domain)
      Write a value in the field domain.
      Parameters:
      domain - The new value for the field domain
    • readCode

      public int readCode()
      Read the value of the field code.
      Returns:
      The value of the field code
    • writeCode

      public void writeCode(int code)
      Write a value in the field code.
      Parameters:
      code - The new value for the field code
    • readMessage

      public String readMessage()
      Read the value of the field message.
      Returns:
      The value of the field message
    • writeMessage

      public void writeMessage(String message, Arena _arena)
      Write a value in the field message.
      Parameters:
      message - The new value for the field message
      _arena - to control the memory allocation scope
    • literal

      public static GError literal(Quark domain, int code, String message)
      Creates a new GError; unlike g_error_new(), message is not a printf()-style format string. Use this function if message contains text you don't have control over, that could include printf() escape sequences.
      Parameters:
      domain - error domain
      code - error code
      message - error message
      Returns:
      a new GError
    • domainRegister

      public static Quark domainRegister(String errorTypeName, long errorTypePrivateSize, @Nullable ErrorInitFunc errorTypeInit, @Nullable ErrorCopyFunc errorTypeCopy, @Nullable ErrorClearFunc errorTypeClear)
      This function registers an extended GError domain. errorTypeName will be duplicated. Otherwise does the same as g_error_domain_register_static().
      Parameters:
      errorTypeName - string to create a GQuark from
      errorTypePrivateSize - size of the private error data in bytes
      errorTypeInit - function initializing fields of the private error data
      errorTypeCopy - function copying fields of the private error data
      errorTypeClear - function freeing fields of the private error data
      Returns:
      GQuark representing the error domain
      Since:
      2.68
    • domainRegisterStatic

      public static Quark domainRegisterStatic(String errorTypeName, long errorTypePrivateSize, @Nullable ErrorInitFunc errorTypeInit, @Nullable ErrorCopyFunc errorTypeCopy, @Nullable ErrorClearFunc errorTypeClear)

      This function registers an extended GError domain.

      errorTypeName should not be freed. errorTypePrivateSize must be greater than 0.

      errorTypeInit receives an initialized GError and should then initialize the private data.

      errorTypeCopy is a function that receives both original and a copy GError and should copy the fields of the private error data. The standard GError fields are already handled.

      errorTypeClear receives the pointer to the error, and it should free the fields of the private error data. It should not free the struct itself though.

      Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it already takes care of passing valid information to this function.

      Parameters:
      errorTypeName - static string to create a GQuark from
      errorTypePrivateSize - size of the private error data in bytes
      errorTypeInit - function initializing fields of the private error data
      errorTypeCopy - function copying fields of the private error data
      errorTypeClear - function freeing fields of the private error data
      Returns:
      GQuark representing the error domain
      Since:
      2.68
    • copy

      public GError copy()
      Makes a copy of error.
      Returns:
      a new GError
    • free

      public void free()
      Frees a GError and associated resources.
    • matches

      public boolean matches(Quark domain, int code)

      Returns true if this Error matches domain and code, false otherwise. In particular, when this Error is null, false will be returned.

      If domain contains a FAILED (or otherwise generic) error code, you should generally not check for it explicitly, but should instead treat any not-explicitly-recognized error code as being equivalent to the FAILED code. This way, if the domain is extended in the future to provide a more specific error code for a certain case, your code will still work.

      Parameters:
      domain - an error domain
      code - an error code
      Returns:
      whether this Error has domain and code