# Custom Error Handling

**URL:** <https://discourse.farcrycore.org/t/custom-error-handling/461>\
**Category:** support\
**Created:** [September 16, 2015, 1:46pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461 "2015-09-16T13:46:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MNM](https://discourse.farcrycore.org/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@MNM](https://discourse.farcrycore.org/u/MNM)\
**Post date:** [September 16, 2015, 1:46pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/1 "2015-09-16T13:46:22Z")

</div>

So whenever we have an issue on one of our sites (public facing), we get an error that looks like an array dump (unfortunately I’m not allowed to upload a picture of the error?). While this is great for debugging purposes, its not a very safe practice to have your database information out there for anyone in the public domain to have. Instead of allowing Farcry to dump this information, is there a way to have it redirect to a generic 404.cfm page?

---

<div class="post-metadata">

**Author:** ![mrfelna](https://discourse.farcrycore.org/user_avatar/discourse.farcrycore.org/mrfelna/32/1217_2.png) [@mrfelna](https://discourse.farcrycore.org/u/mrfelna)\
**Post date:** [September 16, 2015, 2:06pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/2 "2015-09-16T14:06:09Z")

</div>

This depends on your version of FarCry.

In version 7, you can do this very easily. A 500.cfm in either `%project folder%\errors\` or `%project webroot%\errors\` will be displayed instead of the error dump. Similarly a 404.cfm in the same place will be displayed when a page is not found.

Unfortunately, I’m not sure if this was implemented in version 6, but you can always give it a go with a simple test error page.

Good luck!

---

<div class="post-metadata">

**Author:** ![MNM](https://discourse.farcrycore.org/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@MNM](https://discourse.farcrycore.org/u/MNM)\
**Post date:** [September 16, 2015, 2:16pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/3 "2015-09-16T14:16:06Z")

</div>

Unfortunately we are behind the times and working with FC 5.0.2. 😩

---

<div class="post-metadata">

**Author:** ![mrfelna](https://discourse.farcrycore.org/user_avatar/discourse.farcrycore.org/mrfelna/32/1217_2.png) [@mrfelna](https://discourse.farcrycore.org/u/mrfelna)\
**Post date:** [September 16, 2015, 3:24pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/4 "2015-09-16T15:24:04Z")

</div>

I’ll be interested to hear what the other say, but I’d imagine that you’ll have to play around with the OnError function in `%core%\Application.cfc`.

One thing you could try is overriding the function by adding it to `%project webroot%\Application.cfc`, e.g.

```
<cffunction name="OnError" access="public" returntype="void" output="true" hint="Fires when an exception occures that is not caught by a try/catch.">

<cfargument name="Exception" type="any" required="true" />
<cfargument name="EventName" type="string" required="false" default="" />

<cfoutput>Ooops something went wrong!</cfoutput>
<!--- alter as desired --->

</cffunction>
```

---

<div class="post-metadata">

**Author:** ![MNM](https://discourse.farcrycore.org/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@MNM](https://discourse.farcrycore.org/u/MNM)\
**Post date:** [September 16, 2015, 9:30pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/5 "2015-09-16T21:30:11Z")

</div>

Awesome! That seemed to work. I tried putting the function in the %project%/Application.cfc file but it threw a 500 error. No worries though. I edited the cfc in the core. Works great now!

Here’s the code for anyone who is ever interested:

```
<cffunction name="OnError" access="public" returntype="void" output="true" hint="Fires when an exception occures that is not caught by a try/catch.">
	
    	<cfargument name="Exception" type="any" required="true" />
		<cfargument name="EventName" type="string" required="false" default="" />

		<!--- rudimentary error handler --->
		<!--- TODO: need a pretty error handler for the webtop --->
        <!---check for dev/UAT enviornment--->
		<cfif CGI.SERVER_NAME CONTAINS "stage" OR CGI.SERVER_NAME CONTAINS "dev">
            <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/header.cfm" />
            <cfoutput>There was an issue with your request. Please contact us for assistance.</cfoutput>
            <cfdump var="#arguments.exception#" expand="true" label="arguments" />
            <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/footer.cfm" />
		     
        	<cfreturn />   
   		<cfelse>     
			<cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/header.cfm" />
            <cfoutput>There was an issue with your request. Please contact us for assistance.</cfoutput>
           <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/footer.cfm" />
		     
        	<cfreturn />
  
  		</cfif>
 </cffunction>
```

---

<div class="post-metadata">

**Author:** ![mrfelna](https://discourse.farcrycore.org/user_avatar/discourse.farcrycore.org/mrfelna/32/1217_2.png) [@mrfelna](https://discourse.farcrycore.org/u/mrfelna)\
**Post date:** [September 16, 2015, 9:47pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/6 "2015-09-16T21:47:02Z")

</div>

Glad you got it working 😄 A couple of words of warning though:

1. If the error is in the header or footer includes, that particular error handler will break

2. If/when you do upgrade FarCry, you will need to redo the error handling

---

<div class="post-metadata">

**Author:** ![justincarter](https://discourse.farcrycore.org/user_avatar/discourse.farcrycore.org/justincarter/32/1213_2.png) [@justincarter](https://discourse.farcrycore.org/u/justincarter)\
**Post date:** [September 17, 2015, 6:12am UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/7 "2015-09-17T06:12:48Z")

</div>

> [@MNM](#):
>
> Awesome! That seemed to work. I tried putting the function in the %project%/Application.cfc file but it threw a 500 error. No worries though. I edited the cfc in the core. Works great now!

I don’t think there’s any reason that the code would work inside the core/Application.cfc but not in your project’s Application.cfc (after all, your project’s Application.cfc just extends the one from core, via the proxyApplication.cfc). It might be worth another try so that you can avoid modifying the core files.

It would also be a good idea to consider upgrading to FarCry 7.x soon. FarCry 5.x is getting very old and is not really supported any more. Plus FarCry 7 is much nicer to use 😄 Depending on your app upgrading may be fairly straight forward.

---

<div class="post-metadata">

**Author:** ![MNM](https://discourse.farcrycore.org/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@MNM](https://discourse.farcrycore.org/u/MNM)\
**Post date:** [September 17, 2015, 12:57pm UTC](https://discourse.farcrycore.org/t/custom-error-handling/461/8 "2015-09-17T12:57:25Z")

</div>

It’s on our list of projects waiting in queue 😓 . We recently upgraded most of our sites to FC 7 (which is very amazing by the way!) but we ran into issues with our last two sites which are quite large. So the project had to be split into multiple phases because of the short time frame we had initially. Bleh. But definitely looking forward to having an up to date CMS!

By the way, would you know if there is any documentation as to how the admin portion of FC 7 works? I feel like we aren’t utilizing Farcry to the extent it could be…
