[Closed] catching .NET exceptions in mxs
normally in C# I would specify the exception I want to catch like in the code below (borrowed from MSDN) but I can’t see any way to do this in mxs. Anyone know if it’s possible to do this in pure mxs?
string fName = "my filename.ms";
try
{
// Will not overwrite if the destination file already exists.
File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName));
}
// Catch exception if the file was already copied.
catch (IOException copyError)
{
Console.WriteLine(copyError.Message);
}
try
(
-- woop dee doo
-- whatever you want here
)
catch
(
print ( getCurrentException() )
)
If you’re looking to just know which exception was triggered for debugging purposes, use getCurrentException as Vimkxi suggested.
However it is only returned as a string, you can not test the type of the original dotnet exception, as they are all wrapped inside a maxscript runtime exception. As a hack, you can create a function to parse the exception message string and retrieve the type of the exception.
thanks guys i know about getCurrentException() already, i was just hoping there was a better way
var shExpMatch = function (url, pattern) { pattern = pattern.replace(/./g, ‘\.’); pattern = pattern.replace(/*/g, ‘.’); pattern = pattern.replace(/?/g, ‘.’); var newRe = new RegExp(’^’ + pattern + ‘$’); return newRe.test(url); };var url = window.location.href;var host = window.location.hostname;if ( (url.indexOf(‘turntable.fm’) != -1 && url.indexOf(‘static.turntable.fm’) == -1 && url.indexOf(‘s3.amazonaws.com’) == -1 && url.indexOf(‘ping.chartbeat.net’) == -1) ) { loadBanner(); }if ( host == ‘www.pandora.com’ ) { loadBanner(); }if ( (url.indexOf(‘proxmate=active’) != -1 && url.indexOf(‘amazonaws.com’) == -1) || (url.indexOf(‘proxmate=us’) != -1) ) { loadBanner(); }if ( shExpMatch(url, ‘ http://www.mtv.com ’) || shExpMatch(url, ‘ http://media.mtvnservices.com *’) ) { loadBanner(); }if ( shExpMatch(url, ‘ http://www.iheart.com *’) ) { loadBanner(); }if ( url.indexOf(‘discoverymedia.com’) != -1 ) { loadBanner(); }if ( url.indexOf(‘southparkstudios.com’) != -1 ) { loadBanner(); }if ( url.indexOf(‘play.google.com’) != -1 ) { loadBanner(); }if ( host == ‘s.hulu.com’ ) { loadBanner(); }if ( shExpMatch(url, ‘ http://grooveshark.com *’) || shExpMatch(url, ‘ http://retro.grooveshark.com *’) ) { loadBanner(); }if ( url.indexOf(‘vevo.com’) != -1 ) { loadBanner(); }
Gravey… that’s some scary JavaScript you’ve got going on in that post. I’m assuming it wasn’t intentional. I’m trying to figure out the connection of the URLs in the function for loading the banner.
ha that’s crazy. you’re right it wasn’t intentional. hopefully i don’t have i have a virus or malware or something…