Skip to content

Instantly share code, notes, and snippets.

@aylingumus
Created November 23, 2016 10:35
Show Gist options
  • Save aylingumus/9dc5ed5781d2406c3ee3de205eac0449 to your computer and use it in GitHub Desktop.
Save aylingumus/9dc5ed5781d2406c3ee3de205eac0449 to your computer and use it in GitHub Desktop.
Error Alert
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
* {
box-sizing: border-box;
}
main {
padding: 50px 20px;
}
.error-report {
color: red;
}
</style>
</head>
<body>
<main>
<h1>Handling errors</h1>
<p class="error-report js-error-report"></p>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</main>
<script id="jsbin-javascript">
function main() {
try {
doAllTheThings();
}
catch (error) {
console.error(error);
reportError(error);
}
}
function doAllTheThings() {
throw {
message: "Everything's ruined",
name: "FatalException",
toString: function(){return this.name + ": " + this.message;}
}
}
function reportError(e) {
$('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
}
$(main);
</script>
<script id="jsbin-source-css" type="text/css">* {
box-sizing: border-box;
}
main {
padding: 50px 20px;
}
.error-report {
color: red;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">function main() {
try {
doAllTheThings();
}
catch (error) {
console.error(error);
reportError(error);
}
}
function doAllTheThings() {
throw {
message: "Everything's ruined",
name: "FatalException",
toString: function(){return this.name + ": " + this.message;}
}
}
function reportError(e) {
$('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
}
$(main);</script></body>
</html>
function main() {
try {
doAllTheThings();
}
catch (error) {
console.error(error);
reportError(error);
}
}
function doAllTheThings() {
throw {
message: "Everything's ruined",
name: "FatalException",
toString: function(){return this.name + ": " + this.message;}
}
}
function reportError(e) {
$('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
}
$(main);
* {
box-sizing: border-box;
}
main {
padding: 50px 20px;
}
.error-report {
color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment