├── .gitignore ├── README.md ├── clojure └── clojure-example.clj ├── coffeescript └── coffeescript.coffee ├── cpp └── cpp.cpp ├── csharp └── csharp.cs ├── d └── stackoverflowception.d ├── golang ├── golang.go ├── golang_test.go └── gopher.go ├── java └── StackOverflowExceptionExample.java ├── javascript └── javascript.js ├── kotlin └── kotlin.kt ├── livescript └── livescript.ls ├── php └── php.php ├── python ├── alternative.py └── python.py ├── ruby └── ruby.rb ├── scala └── scala.scala ├── swift └── swift.swift ├── typescript └── app.ts └── vbnet └── vbnet.vb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.class 3 | *.exe 4 | *.o 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stackoverflowception 2 | A collection of all the exception handlers that point you to the fitting Stack Overflow tag in as much languages as possible! 3 | 4 | Feel free to fork, add any language and pull request! 5 | 6 | ## What are these handlers for anyway? 7 | 8 | As many of you developers know, Stack Overflow is the source of (most) answers to anything related to programming. 9 | So someone [smart](https://twitter.com/DivineOmega/status/695744177557106688) came up with the idea of writing an exception handler that links you to the Stack Overflow search 10 | with the language tag and the exception message. 11 | 12 | This repository is a fun project to see how many exception handlers for Stack Overflow we can collect together and help 13 | others to get rid of their problems! 14 | 15 | ## How to contribute 16 | 17 | 1. [Fork](https://github.com/pixeldesu/stackoverflowception/fork) this repository 18 | 2. Add the Stack Overflow exception in your language and add it to a subfolder (e.g. `ruby`. `php`...) 19 | 3. Open a [Pull Request](https://github.com/pixeldesu/stackoverflowception/compare)! 20 | 21 | **Note:** If due to library limitations or personal preference, you don't have to include code that it automatically links to the Stack Overflow search page, you can always just print out the link! 22 | -------------------------------------------------------------------------------- /clojure/clojure-example.clj: -------------------------------------------------------------------------------- 1 | (import java.net.URLEncoder) 2 | 3 | (try 4 | (/ 1 0) 5 | (catch Exception e 6 | (->> e 7 | .getMessage 8 | URLEncoder/encode 9 | (format "Please visit http://stackoverflow.com/search?q=%%5Bclojure%%5D%%20%s") 10 | Error. 11 | throw))) 12 | -------------------------------------------------------------------------------- /coffeescript/coffeescript.coffee: -------------------------------------------------------------------------------- 1 | try 2 | # add your breaking code here 3 | catch e 4 | e.message += "\nhttp://stackoverflow.com/search?q=#{encodeURIComponent '[javascript] ' + e.message}\n"; 5 | throw e 6 | 7 | ### 8 | wow! 9 | 10 | open = require 'open' 11 | try 12 | # add your breaking code here 13 | catch e 14 | open "\nhttp://stackoverflow.com/search?q=[coffeescript] #{encodeURIComponent e.message}\n" 15 | throw e 16 | ### 17 | -------------------------------------------------------------------------------- /cpp/cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // compile with -std=c++11 8 | 9 | using namespace std; 10 | 11 | string url_encode(const string &value) { 12 | ostringstream escaped; 13 | escaped.fill('0'); 14 | escaped << hex; 15 | 16 | for (string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) { 17 | string::value_type c = (*i); 18 | 19 | // Keep alphanumeric and other accepted characters intact 20 | if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { 21 | escaped << c; 22 | continue; 23 | } 24 | 25 | // Any other characters are percent-encoded 26 | escaped << uppercase; 27 | escaped << '%' << setw(2) << int((unsigned char) c); 28 | escaped << nouppercase; 29 | } 30 | 31 | return escaped.str(); 32 | } 33 | 34 | int main(){ 35 | try { 36 | throw 1337; 37 | } catch (int e) { 38 | cout << "https://stackoverflow.com/search?q=" << url_encode("[c++] "+to_string(e)) << endl; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /csharp/csharp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | class Program 5 | { 6 | public static void Main(string[] args) 7 | { 8 | try 9 | { 10 | // breaking code: 11 | var x = 0; 12 | Console.WriteLine(5 / x); 13 | } 14 | catch (Exception ex) 15 | { 16 | Process.Start(string.Format("http://stackoverflow.com/search?q=%5Bc%23%5D%20{0}", Uri.EscapeUriString(ex.Message))); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /d/stackoverflowception.d: -------------------------------------------------------------------------------- 1 | import std.stdio; 2 | import std.file; 3 | import std.uri; 4 | 5 | void main(string[] args) { 6 | try { 7 | // breaking code: 8 | read("/thisFileDoesNotExist"); 9 | } catch (Exception e) { 10 | writeln("An error occurred, please visit http://stackoverflow.com/search?q=%5Bd%5D%20", encodeComponent(e.msg)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /golang/golang.go: -------------------------------------------------------------------------------- 1 | package stackoverflowceptionCheck 2 | 3 | import "github.com/pkg/browser" 4 | 5 | func StackoverflowceptionCheck(err error) bool { 6 | if err != nil { 7 | url := "http://stackoverflow.com/search?q=" 8 | url += err.Error() 9 | browser.OpenURL(url) 10 | return true 11 | } 12 | return false 13 | } 14 | -------------------------------------------------------------------------------- /golang/golang_test.go: -------------------------------------------------------------------------------- 1 | package stackoverflowceptionCheck 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestStackoverflowceptionCheck(t *testing.T) { 9 | if !stackoverflowceptionCheck(fmt.Errorf("This is a dummy error")) { 10 | t.Fatalf("Error not catched") 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /golang/gopher.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "runtime" 5 | "fmt" 6 | "os/exec" 7 | "net/url" 8 | ) 9 | 10 | func main() { 11 | defer func() { 12 | if r := recover(); r != nil { 13 | var err string 14 | switch r.(type) { 15 | case string: 16 | err = r.(string) 17 | break 18 | case error: 19 | err = r.(error).Error() 20 | default: 21 | err = fmt.Sprintf("%v", err) 22 | } 23 | 24 | url := fmt.Sprintf("http://stackoverflow.com/search?q=[go]%%20%s", url.QueryEscape(err)) 25 | 26 | var cmd *exec.Cmd 27 | switch runtime.GOOS { 28 | case "windows": 29 | cmd = exec.Command("cmd", "/c", "start", url) 30 | break 31 | case "darwin": 32 | cmd = exec.Command("open", url) 33 | break 34 | default: 35 | cmd = exec.Command("xdg-open", url) 36 | break 37 | } 38 | 39 | cmd.Start() 40 | } 41 | }() 42 | 43 | // naughty code here 44 | } 45 | -------------------------------------------------------------------------------- /java/StackOverflowExceptionExample.java: -------------------------------------------------------------------------------- 1 | import java.net.URLEncoder; 2 | import java.nio.charset.StandardCharsets; 3 | 4 | public class StackOverflowExceptionExample { 5 | public static void main(String[] args) { 6 | try { 7 | // breaking code: 8 | int i = 5 / 0; 9 | } catch (Exception ex) { 10 | String query = String.format("[java] \"%s\"", ex.getMessage()); 11 | 12 | // since Java 10 13 | throw new Error("Please visit http://stackoverflow.com/search?q=" + URLEncoder.encode(query, StandardCharsets.UTF_8)); 14 | 15 | // before Java 10 16 | // throw new Error("Please visit http://stackoverflow.com/search?q=" + URLEncoder.encode(query)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /javascript/javascript.js: -------------------------------------------------------------------------------- 1 | // nice version 2 | try { 3 | // add your breaking code here 4 | } catch(e) { 5 | e.message += `\nhttp://stackoverflow.com/search?q=${encodeURIComponent('[javascript] ' + e.message)}`; 6 | throw e; 7 | } 8 | 9 | // mean version 10 | /* 11 | try { 12 | // add your breaking code here 13 | } catch(e) { 14 | location = 'http://stackoverflow.com/search?q=' + encodeURIComponent('[javascript] ' + e.message); 15 | } 16 | */ 17 | -------------------------------------------------------------------------------- /kotlin/kotlin.kt: -------------------------------------------------------------------------------- 1 | import java.net.URLEncoder 2 | import java.nio.charset.StandardCharsets 3 | 4 | fun main() { 5 | try { 6 | // breaking code: 7 | val i = 5 / 0 8 | } catch (ex: Exception) { 9 | val query = """[java] "${ex.message}"""" 10 | 11 | throw Error("Please visit http://stackoverflow.com/search?q=" + URLEncoder.encode(query, StandardCharsets.UTF_8)) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /livescript/livescript.ls: -------------------------------------------------------------------------------- 1 | # nice version 2 | try 3 | # add your breaking code here 4 | catch 5 | e.message += " (http://stackoverflow.com/search?q=%5Bjavascript%5D%20#{encode-URI-component e.message})" 6 | throw e 7 | 8 | # mean version 9 | /* 10 | try 11 | # add your breaking code here 12 | catch 13 | location = "http://stackoverflow.com/search?q=%5Bjavascript%5D%20#{encode-URI-component e.message}" 14 | */ 15 | -------------------------------------------------------------------------------- /php/php.php: -------------------------------------------------------------------------------- 1 | getMessage())); 9 | 10 | } -------------------------------------------------------------------------------- /python/alternative.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Handle exceptions in a 'with'-block. 4 | Usage: 5 | with handle_exceptions(): 6 | # Breaking code here. 7 | """ 8 | 9 | 10 | import webbrowser 11 | import sys 12 | 13 | if sys.version_info[0] < 3: 14 | from urllib import quote 15 | else: 16 | from urllib.parse import quote 17 | from contextlib import contextmanager 18 | 19 | 20 | @contextmanager 21 | def handle_exceptions(): 22 | """Handle exceptions in a 'with'-block.""" 23 | try: yield 24 | except Exception as e: 25 | url = 'http://stackoverflow.com/search?q=[python] ' + quote(str(e)) 26 | webbrowser.open(url, new=2, autoraise=True) 27 | 28 | with handle_exceptions(): 29 | print(s) 30 | -------------------------------------------------------------------------------- /python/python.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import webbrowser 3 | import sys 4 | if sys.version_info[0] < 3: 5 | from urllib import quote 6 | else: 7 | from urllib.parse import quote 8 | 9 | 10 | try: 11 | print(aylamao) # add your breaking code here 12 | except Exception as e: 13 | url = 'http://stackoverflow.com/search?q=[python] ' + quote(str(e)) 14 | webbrowser.open(url, new=2, autoraise=True) 15 | -------------------------------------------------------------------------------- /ruby/ruby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | puts aylamao # add your breaking code here 4 | rescue Exception => e 5 | exp = e.message.to_s.dup.force_encoding("ASCII-8BIT").gsub(/./) { sprintf("%%%02X", $&.unpack("C")[0]) } 6 | link = "http://stackoverflow.com/search?q=[ruby]" + exp 7 | 8 | if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ 9 | system "start #{link}" 10 | elsif RbConfig::CONFIG['host_os'] =~ /darwin/ 11 | system "open #{link}" 12 | elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ 13 | system "xdg-open #{link}" 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /scala/scala.scala: -------------------------------------------------------------------------------- 1 | object stackoverflowception extends App { 2 | try { 3 | throw new Exception("fUCK") 4 | } catch { 5 | case e: Exception => println("https://stackoverflow.com/search?q="+ java.net.URLEncoder.encode("[scala] " + e, "utf-8")) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /swift/swift.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | do { 4 | let badstr = try NSString(contentsOfFile: "boom-bang.bars.quux", encoding: NSUTF8StringEncoding) 5 | } 6 | catch let error as NSError { 7 | let e = error.localizedDescription as NSString 8 | let encodedErr = e.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()) 9 | if let encodedErr = encodedErr, url = NSURL(string: "http://stackoverflow.com/search?q=[swift]%20\(encodedErr)") { 10 | NSWorkspace.sharedWorkspace().openURL(url) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /typescript/app.ts: -------------------------------------------------------------------------------- 1 | try { 2 | // Do stuffs here 3 | } 4 | catch (e) { 5 | e.message += " http://stackoverflow.com/search?q=${encodeURIComponent('[typescript] ' + e.message)}" 6 | throw new Error(e.message); 7 | } 8 | -------------------------------------------------------------------------------- /vbnet/vbnet.vb: -------------------------------------------------------------------------------- 1 | Imports System.IO 2 | Imports System.Diagnostics 3 | 4 | Module StackOverflowception 5 | Sub Main() 6 | Try 7 | ' breaking code: 8 | File.OpenText("/DoesNotExist") 9 | Catch ex As Exception 10 | Process.Start(String.Format("http://stackoverflow.com/search?q=%5Bvb%5D%20{0}", Uri.EscapeUriString(ex.Message))) 11 | End Try 12 | End Sub 13 | End Module 14 | 15 | --------------------------------------------------------------------------------