[JAVA] Where was the thrown place in the exception stack trace? Where it was generated?

Simplified chart

Depends on where it was thrown

Statically typed language Dynamically typed language
  • C#
  • Ruby
  • Python

Depends on where it was generated

Statically typed language Dynamically typed language
  • Java
  • Scala
  • D
  • PHP

Special

Both information remains

--JavaScript (only ** generated location ** remains as ʻe.stack`)

There are no exceptions in the language standard

Stack trace cannot be taken by language standard

Verification

We are looking for more in the comments section at any time!

Ruby


e = Exception.new
raise e

# test.rb:2:in `<main>': Exception (Exception)

Python


e = Exception
raise e

# Traceback (most recent call last):
#  File "test.py", line 2, in <module>
#    raise e
# Exception

PHP


<?php
$e = new Exception;
throw $e;

/*
PHP Fatal error:  Uncaught Exception in test.php:2
Stack trace:
#0 {main}
  thrown in test.php on line 2
*/

↑ ** thrown in ** appears, but be careful as it is not the place where you threw it

Java


import java.lang.Exception;
class Main
{
	public static void main(String[] args) throws Exception
	{
		Exception e = new Exception();
		throw e;
	}
}

/*
Exception in thread "main" java.lang.Exception
	at Main.main(Main.java:6)
*/

Scala


object Main {
	val e = new Exception
	throw e
}

/*
Exception in thread "main" java.lang.Exception
	at Main$.delayedEndpoint$Main$1(Main.scala:2)
	at Main$delayedInit$body.apply(Main.scala:1)
        ...
*/

JavaScript


e = new Error;
throw e;

/*
test.js:2
throw e;
^

Error
    at Object.<anonymous> (test.js:1:67)
    at Module._compile (module.js:413:34)
*/

Recommended Posts

Where was the thrown place in the exception stack trace? Where it was generated?
When I checked the query generated by Django, it was issued in large numbers
"Exception stack overflow!" In PyMu PDF
Show stack trace with python exception
I wrote the stack in Python
Move the turtle to the place where you click the mouse with turtle in Python