---
title: loadAndReturnError()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/bundle/loadandreturnerror()
---

# loadAndReturnError()

Loads the bundle’s executable code and returns any errors.

## Declaration

```swift
func loadAndReturnError() throws
```

## Discussion

Discussion If this method returns false and you pass a value for the error parameter, a suitable error object is returned in that parameter. Potential errors returned are in the Cocoa error domain and include the types that follow. For a full list of error types, see FoundationErrors.h. NSFileNoSuchFileError - returned if the bundle’s executable file was not located. NSExecutableNotLoadableError - returned if the bundle’s executable file exists but could not be loaded. This error is returned if the executable is not recognized as a loadable executable. It can also be returned if the executable is a PEF/CFM executable but the current process does not support that type of executable. NSExecutableArchitectureMismatchError - returned if the bundle executable does not include code that matches the processor architecture of the current processor. NSExecutableRuntimeMismatchError - returned if the bundle’s required Objective-C runtime information is not compatible with the runtime of the current process. NSExecutableLoadError - returned if the bundle’s executable failed to load for some detectable reason prior to linking. This error might occur if the bundle depends on a framework or library that is missing or if the required framework or library is not compatible with the current architecture or runtime version. NSExecutableLinkError - returned if the executable failed to load due to link errors but is otherwise alright. The error object may contain additional debugging information in its description that you can use to identify the cause of the error. (This debugging information should not be displayed to the user.) You can obtain the debugging information by invoking the error object’s description method in your code or by using the print-object command on the error object in gdb. note: In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Loading code from a bundle

- [executableArchitectures](foundation/bundle/executablearchitectures.md)
- [preflight()](foundation/bundle/preflight().md)
- [load()](foundation/bundle/load().md)
- [unload()](foundation/bundle/unload().md)
- [isLoaded](foundation/bundle/isloaded.md)
- [Mach-O Architecture](foundation/1495005-mach-o-architecture.md)
