Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created January 12, 2012 09:23
Show Gist options
  • Save Integralist/1599546 to your computer and use it in GitHub Desktop.
Save Integralist/1599546 to your computer and use it in GitHub Desktop.
Error Handling with RequireJs
define(function(){
return function(errObject) {
requireType = errObject.requireType;
requireModules = errObject.requireModules.trim().split(' ');
console.log(requireType, requireModules);
};
});
require.config({
catchError: {
define: true
}
});
require(['errorhandler'], function(handler) {
console.log('error handler loaded');
require.onError = handler;
});
require(['module-with-dependancy-issue'], function(mod) {
console.log(mod);
});
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<title>Require Js</title>
</head>
<body>
<h1>Error Handling</h1>
<script data-main="Assets/Scripts/example-error-handling" src="Assets/Scripts/Require.min.js"></script>
</body>
</html>
define(['this-doesnt-exist'], function(){
return 'my module';
});
@infacq
Copy link

infacq commented May 9, 2014

how do I avoid this error

Uncaught TypeError: Cannot read property 'trim' of null 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment