InitError

InitError(mod::Symbol, error)

An error occurred when running a module's __init__ function. The actual error thrown is available in the .error field.

Examples

In the Julia programming language, the InitError function is used to represent an error that occurred when running a module's __init__ function. The specific error thrown can be accessed through the .error field of the InitError object.

julia> module MyModule
           function __init__()
               # Code that may throw an error during module initialization
               throw(ArgumentError("Invalid argument"))
           end
       end
ERROR: LoadError: InitError(MyModule, ArgumentError("Invalid argument"))
Stacktrace:
...

In the example above, an ArgumentError is thrown during the initialization of the MyModule module. This results in an InitError being raised with the module symbol (MyModule) and the specific error (ArgumentError("Invalid argument")).

To access the error thrown within the InitError, you can use the .error field:

julia> try
           using MyModule
       catch err
           if err isa InitError
               println("Error occurred during module initialization:")
               println(err.error)  # Access the specific error
           else
               rethrow(err)
           end
       end
Error occurred during module initialization:
Invalid argument

In this example, we catch the InitError and print the specific error using err.error. This allows you to handle and access the underlying error that occurred during module initialization.

Please note that the InitError function is typically not called directly by the user, but rather raised automatically when an error occurs during module initialization.

See Also

ArgumentError, AssertionError, BoundsError, DivideError, DomainError, EOFError, error, ErrorException, InexactError, InitError, KeyError, LoadError, MethodError, OutOfMemoryError, OverflowError, ParseError, ReadOnlyMemoryError, showerror, StackOverflowError, SystemError, TypeError, UndefRefError, UndefVarError,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: