HadErrors
---------

Queries error counter.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Plugin](component_Plugin.md) | [12.2](newinversion122.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "HadErrors" ) ### Parameters

none

### Result

Returns number or error.

### Description

Queries error counter.  
Call this on the end of a script to query how many errors happened.   
You need to call [ClearErrors](ClearErrors.md) function before on the start of the script to reset counter.  
Use [ErrorLog](ErrorLog.md) function to read the log.  
  
The counter increases whenever a plugin function returns an error.  
See also [IsError](IsError.md) function.  
  
Errors are tracked per thread, so on a server each PSoS session has its own error log. And it includes errors from subscripts.  
### Examples

Log errors from FileMaker and MBS to a table:

 # LogErrors in file HotKeys   
  
\# check for FileMaker errors   
Set Variable \[ $path ; Value: MBS ("[Path.AddPathComponent](PathAddPathComponent.md)"; MBS ("[Folders.UserDocuments](FoldersUserDocuments.md)"); "ScriptErrors.log") \]  
If \[ MBS ("[Files.FileExists](FilesFileExists.md)"; $path ) \]  
 # save the content of FileMaker's log file to the database table  
 Set Variable \[ $r ; Value: MBS ("[FM.InsertRecord](FMInsertRecord.md)"; Get(FileName); "Errors"; "Details"; MBS ("[Text.ReadTextFile](TextReadTextFile.md)"; $path ; "UTF-8")) \]  
 # make sure FileMaker makes a new file next time  
 Set Error Logging \[ Off \]  
 # delete the file  
 Set Variable \[ $r ; Value: MBS ("[Files.Delete](FilesDelete.md)"; $path ) \]  
End If  
\# check for MBS errors on the way   
If \[ MBS ("HadErrors") &gt; 0 \]  
 Set Variable \[ $Log ; Value: MBS ( "ErrorLog") \]  
 # and write the JSON to a table  
 Set Variable \[ $r ; Value: MBS ("[FM.InsertRecord](FMInsertRecord.md)"; Get(FileName); "Errors"; "Details"; $Log ) \]  
End If  
### See also

- [ErrorLog](ErrorLog.md)
- [Files.Delete](FilesDelete.md)
- [Files.FileExists](FilesFileExists.md)
- [FM.InsertRecord](FMInsertRecord.md)
- [Folders.UserDocuments](FoldersUserDocuments.md)
- [Path.AddPathComponent](PathAddPathComponent.md)
- [Text.ReadTextFile](TextReadTextFile.md)

### Release notes

- **Version 12.2**
    - Added [ClearErrors](https://mbsplugins.eu/ClearErrors.shtml) and [HadErrors](https://mbsplugins.eu/HadErrors.shtml) functions.

### Blog Entries

- [MBS @ FMTraining.TV - The FileMaker MonkeyBread Plug-in Q&amp;A](https://www.mbsplugins.de/archive/2024-07-03/MBS_@_FMTrainingTV_-_The_FileM/monkeybreadsoftware_blog_filemaker)
- [MBS @ FMTraining.TV - Error Capturing with the MBS Plugin - FileMaker MBS Q&amp;A](https://www.mbsplugins.de/archive/2024-03-21/MBS_@_FMTrainingTV_-_Error_Cap/monkeybreadsoftware_blog_filemaker)
- [FileMaker and MongoDB](https://www.mbsplugins.de/archive/2023-03-20/FileMaker_and_MongoDB/monkeybreadsoftware_blog_filemaker)
- [Top 10 from the MBS Plugin in 2022](https://www.mbsplugins.de/archive/2022-12-29/Top_10_from_the_MBS_Plugin_in_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 12.3](https://www.mbsplugins.de/archive/2022-07-19/MBS_FileMaker_Plugin_123/monkeybreadsoftware_blog_filemaker)
- [New error log functions for FileMaker](https://www.mbsplugins.de/archive/2022-06-23/New_error_log_functions_for_Fi/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 12.2](https://www.mbsplugins.de/archive/2022-06-09/MBS_FileMaker_Plugin_122/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 12.2 for Claris FileMaker](https://www.mbsplugins.de/archive/2022-05-17/MBS_Plugin_122_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [Transactions with SQL functions](https://www.mbsplugins.de/archive/2022-04-28/Transactions_with_SQL_function/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.2pr4](https://www.mbsplugins.de/archive/2022-04-28/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 28th April 2022 , last changed 25th February 2026

  
[GetSystemUIModeOptions](GetSystemUIModeOptions.md) - [Hash.CRC16](HashCRC16.md)

[HTML Version](HadErrors.shtml)