SystemError(prefix::AbstractString, [errno::Int32])

A system call failed with an error code (in the errno global variable).


In the Julia programming language, the function systemerror(sysfunc, iftrue)

Raises a SystemError with the specified errno and descriptive string sysfunc if iftrue evaluates to true.

julia> systemerror("open", true)
ERROR: SystemError (with open): opening file failed

Common examples of its use:

  1. Check if a file exists and raise an error if not:

    julia> filename = "example.txt";
    julia> if !isfile(filename)
              systemerror("open", true)

    In this example, if the file "example.txt" does not exist, a SystemError is raised with the descriptive string "open".

  2. Raise an error for an invalid user input:

    julia> user_input = -5;
    julia> if user_input < 0
              systemerror("input validation", true)

    If the user_input is negative, a SystemError is raised with the descriptive string "input validation".

  3. Handle a specific system error condition:

    julia> result = perform_operation();
    julia> if result == -1
              systemerror("system resource unavailable", true)

    If the perform_operation() returns -1, indicating a specific system error condition, a SystemError is raised with the descriptive string "system resource unavailable".

Common mistake example:

julia> systemerror(5, true)
ERROR: TypeError: in systemerror, expected argument sysfunc to be a String, got Int64

In this example, the sysfunc argument is expected to be a string, but an integer is provided instead. Ensure that the sysfunc argument is of type String when using the systemerror function.

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

Checking you are not a robot: