We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
They aren't keywords. "Error" is the name given to the exception being caught (any will work, assuming the name being attempted isn't a keyword), "exception" is a generic exception type, and "bad_alloc" is a subtype of exception specific to bad memory allocation. The ampersand at the end of both "bad_alloc" and "exception" is a case of passing by reference, since 1)the overhead from passing around entire copies of the exceptions would be prohibitive, and 2)the example answer provided is following the adage of "throw by value, catch by reference," which is important for preserving the errors being thrown (according to https://stackoverflow.com/a/2522311, at least).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Exceptional Server
You are viewing a single comment's thread. Return to all comments →
They aren't keywords. "Error" is the name given to the exception being caught (any will work, assuming the name being attempted isn't a keyword), "exception" is a generic exception type, and "bad_alloc" is a subtype of exception specific to bad memory allocation. The ampersand at the end of both "bad_alloc" and "exception" is a case of passing by reference, since 1)the overhead from passing around entire copies of the exceptions would be prohibitive, and 2)the example answer provided is following the adage of "throw by value, catch by reference," which is important for preserving the errors being thrown (according to https://stackoverflow.com/a/2522311, at least).