Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
79e16252
Commit
79e16252
authored
Jun 14, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #286 from monaka/pr-simplify-error-c
Simplify error.c
parents
93cabfc1
cfd5f515
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
31 deletions
+56
-31
mrblib/error.rb
mrblib/error.rb
+8
-0
src/error.c
src/error.c
+18
-31
test/t/exception.rb
test/t/exception.rb
+30
-0
No files found.
mrblib/error.rb
View file @
79e16252
...
...
@@ -17,5 +17,13 @@ end
class
ScriptError
<
Exception
end
# ISO 15.2.38
class
SyntaxError
<
ScriptError
end
# ISO 15.2.39
class
LoadError
<
ScriptError
end
class
NotImplementedError
<
ScriptError
end
src/error.c
View file @
79e16252
...
...
@@ -172,25 +172,20 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc)
longjmp
(
*
(
jmp_buf
*
)
mrb
->
jmp
,
1
);
}
void
mrb_raise_va
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
fmt
,
va_list
args
)
{
char
buf
[
256
];
vsnprintf
(
buf
,
256
,
fmt
,
args
);
mrb_exc_raise
(
mrb
,
mrb_exc_new
(
mrb
,
c
,
buf
,
strlen
(
buf
)));
}
void
mrb_raise
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
fmt
,
...)
{
va_list
args
;
char
buf
[
256
];
int
n
;
va_start
(
args
,
fmt
);
vsnprintf
(
buf
,
256
,
fmt
,
args
);
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
va_end
(
args
);
mrb_exc_raise
(
mrb
,
mrb_exc_new
(
mrb
,
c
,
buf
,
strlen
(
buf
)));
if
(
n
<
0
)
{
n
=
0
;
}
mrb_exc_raise
(
mrb
,
mrb_exc_new
(
mrb
,
c
,
buf
,
n
));
}
void
...
...
@@ -199,12 +194,15 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...)
mrb_value
exc
,
argv
[
2
];
va_list
args
;
char
buf
[
256
];
int
n
;
va_start
(
args
,
fmt
);
//argv[0] = mrb_vsprintf(fmt, args);
vsnprintf
(
buf
,
256
,
fmt
,
args
);
argv
[
0
]
=
mrb_str_new
(
mrb
,
buf
,
strlen
(
buf
));
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
va_end
(
args
);
if
(
n
<
0
)
{
n
=
0
;
}
argv
[
0
]
=
mrb_str_new
(
mrb
,
buf
,
n
);
argv
[
1
]
=
mrb_str_new_cstr
(
mrb
,
mrb_sym2name
(
mrb
,
id
));
exc
=
mrb_class_new_instance
(
mrb
,
2
,
argv
,
E_NAME_ERROR
);
...
...
@@ -216,11 +214,15 @@ mrb_sprintf(mrb_state *mrb, const char *fmt, ...)
{
va_list
args
;
char
buf
[
256
];
int
n
;
va_start
(
args
,
fmt
);
vsnprintf
(
buf
,
256
,
fmt
,
args
);
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
va_end
(
args
);
return
mrb_str_new
(
mrb
,
buf
,
strlen
(
buf
));
if
(
n
<
0
)
{
n
=
0
;
}
return
mrb_str_new
(
mrb
,
buf
,
n
);
}
void
...
...
@@ -236,18 +238,6 @@ mrb_warn(const char *fmt, ...)
}
void
mrb_warning
(
const
char
*
fmt
,
...)
{
va_list
args
;
char
buf
[
256
];
va_start
(
args
,
fmt
);
snprintf
(
buf
,
256
,
"warning: %s"
,
fmt
);
printf
(
buf
,
args
);
va_end
(
args
);
}
void
mrb_bug
(
const
char
*
fmt
,
...)
{
...
...
@@ -395,9 +385,6 @@ mrb_init_exception(mrb_state *mrb)
eNameError
=
mrb_define_class
(
mrb
,
"NameError"
,
mrb
->
eStandardError_class
);
/* 15.2.31 */
mrb_define_class
(
mrb
,
"NoMethodError"
,
eNameError
);
/* 15.2.32 */
// eScriptError = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */
// mrb_define_class(mrb, "SyntaxError", eScriptError); /* 15.2.38 */
// mrb_define_class(mrb, "LoadError", eScriptError); /* 15.2.39 */
// mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */
mrb_define_class
(
mrb
,
"LocalJumpError"
,
mrb
->
eStandardError_class
);
/* 15.2.25 */
...
...
test/t/exception.rb
View file @
79e16252
...
...
@@ -41,6 +41,36 @@ assert('Exception.exception', '15.2.22.4.1') do
e
.
message
==
'a'
end
assert
(
'ScriptError'
,
'15.2.37'
)
do
begin
raise
ScriptError
.
new
rescue
ScriptError
true
else
false
end
end
assert
(
'SyntaxError'
,
'15.2.38'
)
do
begin
raise
SyntaxError
.
new
rescue
SyntaxError
true
else
false
end
end
assert
(
'LoadError'
,
'15.2.39'
)
do
begin
raise
LoadError
.
new
rescue
LoadError
true
else
false
end
end
# Not ISO specified
assert
(
'Exception 1'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment