Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active March 9, 2019 16:06
Show Gist options
  • Save appkr/af67e43155cc85ba1a3c2609b1393412 to your computer and use it in GitHub Desktop.
Save appkr/af67e43155cc85ba1a3c2609b1393412 to your computer and use it in GitHub Desktop.
Stack Trace Example
<?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 '이 라인은 출력되지 않습니다';
}
<?php
foo();
function foo() {
bar();
}
function bar() {
baz();
}
function baz() {
throw new RuntimeException('런타임 예외가 발생했습니다');
echo '이 라인은 출력되지 않습니다';
}
<?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 '이 라인은 출력되지 않습니다';
}
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);
}
}
}
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("사용자 정의 예외가 발생했습니다");
}
}
<?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;
}
# -*- 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)
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