Socket.SetErrorHandler
----------------------

Sets the error handler for this socket.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Socket](component_Socket.md) | [3.1](newinversion31.md) | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes |

MBS( "Socket.SetErrorHandler"; SocketID; FileName; ScriptName ) 

**MBS**( **"Socket.SetErrorHandler";** /\* Sets the error handler for this socket. \*/  
**$SocketID**; /\* The socket ID received by [Socket.Connect](SocketConnect.md) function.e.g. $sock \*/   
**$FileName**; /\* The name of the FileMaker File that contains the scripte.g. "MyDatabase.fp7" \*/   
**$ScriptName**) /\* The name of the script to rune.g. "SocketError" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SocketID | The socket ID received by [Socket.Connect](SocketConnect.md) function. | $sock |
| FileName | The name of the FileMaker File that contains the script | "MyDatabase.fp7" |
| ScriptName | The name of the script to run | "SocketError" |

### Result

Returns OK or error message.

### Description

Sets the error handler for this socket.  
If the socket has an error, this script is called and you can react and close the socket.  
  
  
With plugin version 6.0 or newer the script name can be a script ID number. In that case the plugin queries the script name for the given script ID. This allows to call scripts by ID and avoid problems if scripts are later renamed.  
  
Notice: FileMaker 19.2 adds a fmplugin extended privileges. If you have such an extended privileges to allow the plugin to trigger scripts, you need to grant permissions for it. If such a privilege is not defined, the plugin is allowed to trigger scripts. See FileMaker product documentation for details.  
### Examples

Create TCP Socket listening on a port:

 Set Variable \[$$sock ; Value:MBS ("[Socket.NewTCPSocket](SocketNewTCPSocket.md)")\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["Failed to create Socket"; $$sock \]  
 Exit Script \[\]  
End If  
Set Variable \[$r ; Value:MBS ("[Socket.SetNewConnectionHandler](SocketSetNewConnectionHandler.md)"; $$sock ; Get(FileName); "NewConnection")\]  
Set Variable \[$r ; Value:MBS ("Socket.SetErrorHandler"; $$sock ; Get(FileName); "SocketError")\]  
Set Variable \[$r ; Value:MBS ("[Socket.Listen](SocketListen.md)"; $$sock ; TCP Receiver::ListenPort )\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["Failed to create Socket"; $$sock \]  
 Exit Script \[\]  
End If  
### See also

- [IsError](IsError.md)
- [Socket.AcceptNewConnection](SocketAcceptNewConnection.md)
- [Socket.ClearErrorHandler](SocketClearErrorHandler.md)
- [Socket.Connect](SocketConnect.md)
- [Socket.List](SocketList.md)
- [Socket.Listen](SocketListen.md)
- [Socket.NewTCPSocket](SocketNewTCPSocket.md)
- [Socket.SetNewConnectionHandler](SocketSetNewConnectionHandler.md)

### Example Databases

- [Network/HTTP Server hosted](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/HTTP%20Server%20hosted.shtml#1ScriptAnchor_)
- [Network/HTTP Server local](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/HTTP%20Server%20local.shtml#1ScriptAnchor_)
- [Network/Socket Test/Socket Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/Socket%20Test/Socket%20Test.shtml#1ScriptAnchor_)
- [Network/TCP Send and Receive/TCP Receiver](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/TCP%20Send%20and%20Receive/TCP%20Receiver.shtml#1ScriptAnchor_)
- [Network/TCP Send and Receive/TCP Sender](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/TCP%20Send%20and%20Receive/TCP%20Sender.shtml#1ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 17th June 2018

  
[Socket.SetErrorEvaluate](SocketSetErrorEvaluate.md) - [Socket.SetErrorURL](SocketSetErrorURL.md)

[HTML Version](SocketSetErrorHandler.shtml)