---
title: "What is the use of on_load() in Erlang programming?"  
description: "What is the use of on_load() in Erlang programming?"  
author: "Tarun Kumar"  
published: 2016-02-23  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/22988/what-is-the-use-of-on_load-in-erlang-programming  
category: "erlang"  
tags: ["erlang"]  
reading_time: 2 minutes  

---

# What is the use of on_load() in Erlang programming?

The on_load directive name is a function which will run automatically whenever a module is loaded. If we use on_load() function then it is not necessary to export the function because when on_load() function will call it will create a newly spawned process (means: it will generate a new process) and the function must return ***ok*** if the module is to remain loaded and become callable.It will generate an exception also causes the module to be unloaded.\
If the return value is not an atom then a warning error report will be sent to the error logger. and until the on_load() function returns ***ok*** the system will not terminated.\
Syntax:\
***-on_load(Function_Name/0).***\

## Answers

### Answer by Tarun Kumar

The on_load directive name is a function which will run automatically whenever a module is loaded. If we use on_load() function then it is not necessary to export the function because when on_load() function will call it will create a newly spawned process (means: it will generate a new process) and the function must return ***ok*** if the module is to remain loaded and become callable.It will generate an exception also causes the module to be unloaded.\
If the return value is not an atom then a warning error report will be sent to the error logger. and until the on_load() function returns ***ok*** the system will not terminated.\
Syntax:\
***-on_load(Function_Name/0).***\


---

Original Source: https://www.mindstick.com/interview/22988/what-is-the-use-of-on_load-in-erlang-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
