Last active
March 9, 2019 16:06
-
-
Save appkr/af67e43155cc85ba1a3c2609b1393412 to your computer and use it in GitHub Desktop.
Stack Trace Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
foo(); | |
} catch (RuntimeException $e) { | |
throw new CustomException('사용자 정의 예외가 발생했습니다'); | |
} | |
class CustomException extends RuntimeException {} | |
function foo() { | |
bar(); | |
} | |
function bar() { | |
baz(); | |
} | |
function baz() { | |
throw new RuntimeException('런타임 예외가 발생했습니다'); | |
echo '이 라인은 출력되지 않습니다'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foo(); | |
function foo() { | |
bar(); | |
} | |
function bar() { | |
baz(); | |
} | |
function baz() { | |
throw new RuntimeException('런타임 예외가 발생했습니다'); | |
echo '이 라인은 출력되지 않습니다'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
foo(); | |
} catch (RuntimeException $e) { | |
throw new CustomException('사용자 정의 예외가 발생했습니다', null, $e); | |
} | |
class CustomException extends RuntimeException {} | |
function foo() { | |
bar(); | |
} | |
function bar() { | |
baz(); | |
} | |
function baz() { | |
throw new RuntimeException('런타임 예외가 발생했습니다'); | |
echo '이 라인은 출력되지 않습니다'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomException extends RuntimeException { | |
public CustomException(String message, Throwable previous) { | |
super(message, previous); | |
} | |
} | |
public class main { | |
static void foo() { | |
bar(); | |
} | |
static void bar() { | |
baz(); | |
} | |
static void baz() { | |
throw new RuntimeException("런타임 예외가 발생했습니다"); | |
// System.out.println("이 라인은 컴파일 오류를 일으킵니다"); | |
} | |
public static void main(String[] args) { | |
try { | |
foo(); | |
} catch (RuntimeException e) { | |
throw new CustomException("사용자 정의 예외가 발생했습니다", e); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomError extends Error { | |
constructor(message) { | |
super(message); | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(this, CustomError); | |
} | |
} | |
} | |
function foo() { | |
bar(); | |
} | |
function bar() { | |
baz(); | |
} | |
function baz() { | |
throw new Error("런타임 예외가 발생했습니다"); | |
console.log("이 라인은 출력되지 않습니다"); | |
} | |
try { | |
foo(); | |
} catch (e) { | |
if (e instanceof Error) { | |
throw new CustomError("사용자 정의 예외가 발생했습니다"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foo(); | |
function foo() { | |
echo '1', PHP_EOL; | |
bar(); | |
echo '5', PHP_EOL; | |
} | |
function bar() { | |
echo '2', PHP_EOL; | |
baz(); | |
echo '4', PHP_EOL; | |
} | |
function baz() { | |
echo '3', PHP_EOL; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class CustomError(RuntimeError): | |
def __init__(self, message, other): | |
super(CustomError, self).__init__(other.message) | |
def foo(): | |
bar() | |
def bar(): | |
baz() | |
def baz(): | |
raise RuntimeError('런타임 예외가 발생했습니다') | |
print('이 라인은 출력되지 않습니다') | |
try: | |
foo() | |
except RuntimeError as e: | |
raise CustomError('사용자 정의 예외가 발생했습니다', e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomError < RuntimeError | |
end | |
def foo() | |
bar() | |
end | |
def bar() | |
baz() | |
end | |
def baz() | |
raise RuntimeError.new('사용자 정의 예외가 발생했습니다') | |
p '이 라인은 출력되지 않습니다' | |
end | |
begin | |
foo() | |
rescue | |
raise CustomError.new('사용자 정의 예외가 발생했습니다') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment